Skip to content

Commit 29f02a2

Browse files
author
eugenp
committed
persistence cleanup
1 parent 0d5f88e commit 29f02a2

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

spring-jpa/src/main/java/org/baeldung/spring/PersistenceJPAConfig.java renamed to spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfig.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.baeldung.spring;
1+
package org.baeldung.config;
22

33
import java.util.Properties;
44

@@ -8,6 +8,7 @@
88
import org.springframework.beans.factory.annotation.Autowired;
99
import org.springframework.context.annotation.Bean;
1010
import org.springframework.context.annotation.ComponentScan;
11+
import org.springframework.context.annotation.Configuration;
1112
import org.springframework.context.annotation.PropertySource;
1213
import org.springframework.core.env.Environment;
1314
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
@@ -20,7 +21,7 @@
2021

2122
import com.google.common.base.Preconditions;
2223

23-
// @Configuration
24+
@Configuration
2425
@EnableTransactionManagement
2526
@PropertySource({ "classpath:persistence-mysql.properties" })
2627
@ComponentScan({ "org.baeldung.persistence" })
@@ -33,14 +34,15 @@ public PersistenceJPAConfig() {
3334
super();
3435
}
3536

37+
// beans
38+
3639
@Bean
3740
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() {
3841
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
3942
em.setDataSource(dataSource());
4043
em.setPackagesToScan(new String[] { "org.baeldung.persistence.model" });
4144

4245
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
43-
// vendorAdapter.set
4446
em.setJpaVendorAdapter(vendorAdapter);
4547
em.setJpaProperties(additionalProperties());
4648

spring-jpa/src/main/java/org/baeldung/spring/PersistenceJPAConfigXml.java renamed to spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfigXml.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
package org.baeldung.spring;
1+
package org.baeldung.config;
22

33
import org.springframework.context.annotation.ComponentScan;
4-
import org.springframework.context.annotation.Configuration;
54
import org.springframework.context.annotation.ImportResource;
65
import org.springframework.transaction.annotation.EnableTransactionManagement;
76

8-
@Configuration
7+
// @Configuration
98
@EnableTransactionManagement
109
@ComponentScan({ "org.baeldung.persistence" })
1110
@ImportResource({ "classpath:jpaConfig.xml" })

spring-jpa/src/main/java/org/baeldung/persistence/service/FooService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ public void create(final Foo entity) {
2323
dao.create(entity);
2424
}
2525

26+
public Foo findOne(final long id) {
27+
return dao.findOne(id);
28+
}
29+
2630
}

spring-jpa/src/test/java/org/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
44

5+
import org.baeldung.config.PersistenceJPAConfig;
56
import org.baeldung.persistence.model.Foo;
6-
import org.baeldung.spring.PersistenceJPAConfig;
7+
import org.junit.Assert;
78
import org.junit.Test;
89
import org.junit.runner.RunWith;
910
import org.springframework.beans.factory.annotation.Autowired;
@@ -55,4 +56,12 @@ public final void temp_whenInvalidEntityIsCreated_thenDataException() {
5556
service.create(new Foo());
5657
}
5758

59+
@Test
60+
public final void whenEntityIsCreated_thenFound() {
61+
final Foo fooEntity = new Foo("abc");
62+
service.create(fooEntity);
63+
final Foo found = service.findOne(fooEntity.getId());
64+
Assert.assertNotNull(found);
65+
}
66+
5867
}

0 commit comments

Comments
 (0)