BAEL-2306: Update Spring JNDI article (#5540)
This commit is contained in:
parent
84ef2cd246
commit
0987f52a88
|
@ -23,23 +23,19 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|||
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
@PropertySource({ "classpath:persistence-jndi.properties" })
|
||||
@ComponentScan({ "org.baeldung.persistence" })
|
||||
@PropertySource("classpath:persistence-jndi.properties")
|
||||
@ComponentScan("org.baeldung.persistence")
|
||||
@EnableJpaRepositories(basePackages = "org.baeldung.persistence.dao")
|
||||
public class PersistenceJNDIConfig {
|
||||
|
||||
@Autowired
|
||||
private Environment env;
|
||||
|
||||
public PersistenceJNDIConfig() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws NamingException {
|
||||
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
|
||||
em.setDataSource(dataSource());
|
||||
em.setPackagesToScan(new String[] { "org.baeldung.persistence.model" });
|
||||
em.setPackagesToScan("org.baeldung.persistence.model");
|
||||
em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
|
||||
em.setJpaProperties(additionalProperties());
|
||||
return em;
|
||||
|
@ -52,9 +48,7 @@ public class PersistenceJNDIConfig {
|
|||
|
||||
@Bean
|
||||
public PlatformTransactionManager transactionManager(final EntityManagerFactory emf) {
|
||||
final JpaTransactionManager transactionManager = new JpaTransactionManager();
|
||||
transactionManager.setEntityManagerFactory(emf);
|
||||
return transactionManager;
|
||||
return new JpaTransactionManager(emf);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
|
|
@ -25,7 +25,7 @@ public class Foo implements Serializable {
|
|||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
@Column(name = "ID")
|
||||
private long id;
|
||||
private Long id;
|
||||
@Column(name = "NAME")
|
||||
private String name;
|
||||
|
||||
|
@ -41,11 +41,11 @@ public class Foo implements Serializable {
|
|||
this.bar = bar;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final int id) {
|
||||
public void setId(final Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue