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
|
@Configuration
|
||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
@PropertySource({ "classpath:persistence-jndi.properties" })
|
@PropertySource("classpath:persistence-jndi.properties")
|
||||||
@ComponentScan({ "org.baeldung.persistence" })
|
@ComponentScan("org.baeldung.persistence")
|
||||||
@EnableJpaRepositories(basePackages = "org.baeldung.persistence.dao")
|
@EnableJpaRepositories(basePackages = "org.baeldung.persistence.dao")
|
||||||
public class PersistenceJNDIConfig {
|
public class PersistenceJNDIConfig {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private Environment env;
|
private Environment env;
|
||||||
|
|
||||||
public PersistenceJNDIConfig() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws NamingException {
|
public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws NamingException {
|
||||||
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
|
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
|
||||||
em.setDataSource(dataSource());
|
em.setDataSource(dataSource());
|
||||||
em.setPackagesToScan(new String[] { "org.baeldung.persistence.model" });
|
em.setPackagesToScan("org.baeldung.persistence.model");
|
||||||
em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
|
em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
|
||||||
em.setJpaProperties(additionalProperties());
|
em.setJpaProperties(additionalProperties());
|
||||||
return em;
|
return em;
|
||||||
|
@ -52,9 +48,7 @@ public class PersistenceJNDIConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public PlatformTransactionManager transactionManager(final EntityManagerFactory emf) {
|
public PlatformTransactionManager transactionManager(final EntityManagerFactory emf) {
|
||||||
final JpaTransactionManager transactionManager = new JpaTransactionManager();
|
return new JpaTransactionManager(emf);
|
||||||
transactionManager.setEntityManagerFactory(emf);
|
|
||||||
return transactionManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class Foo implements Serializable {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
@Column(name = "ID")
|
@Column(name = "ID")
|
||||||
private long id;
|
private Long id;
|
||||||
@Column(name = "NAME")
|
@Column(name = "NAME")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@ -41,11 +41,11 @@ public class Foo implements Serializable {
|
||||||
this.bar = bar;
|
this.bar = bar;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(final int id) {
|
public void setId(final Long id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue