Skip to content

Commit a9645c0

Browse files
amit2103pivovarit
authored andcommitted
Fixed integration test of spring-jpa module through inmemory H2 DB (eugenp#4740)
* [BAEL-7621] - Fixed integration test of spring-hibernate-5 module by introducing H2 database * [BAEL-7645] - Fixed integration test of spring-jpa module through H2 inmemory DB
1 parent bfb333d commit a9645c0

20 files changed

Lines changed: 45 additions & 18 deletions

‎persistence-modules/spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfig.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
@Configuration
2626
@EnableTransactionManagement
27-
@PropertySource({ "classpath:persistence-mysql.properties" })
27+
@PropertySource({ "classpath:persistence-h2.properties" })
2828
@ComponentScan({ "org.baeldung.persistence" })
2929
@EnableJpaRepositories(basePackages = "org.baeldung.persistence.dao")
3030
public class PersistenceJPAConfig {

‎persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/multiple/model/user/Possession.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
public class Possession {
1212

1313
@Id
14-
@GeneratedValue(strategy = GenerationType.AUTO)
14+
@GeneratedValue(strategy = GenerationType.IDENTITY)
1515
private long id;
1616

1717
private String name;

‎persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/multiple/model/user/User.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
public class User {
1616

1717
@Id
18-
@GeneratedValue(strategy = GenerationType.AUTO)
18+
@GeneratedValue(strategy = GenerationType.IDENTITY)
1919
private int id;
2020

2121
private String name;

‎persistence-modules/spring-jpa/src/main/resources/persistence-h2.properties‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
jdbc.driverClassName=org.h2.Driver
33
jdbc.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
44
jdbc.user=sa
5-
# jdbc.pass=
5+
jdbc.pass=
66

77
# hibernate.X
88
hibernate.dialect=org.hibernate.dialect.H2Dialect

‎persistence-modules/spring-jpa/src/main/resources/persistence-multiple-db.properties‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# jdbc.X
2-
jdbc.driverClassName=com.mysql.cj.jdbc.Driver
3-
user.jdbc.url=jdbc:mysql://localhost:3306/spring_jpa_user?createDatabaseIfNotExist=true
4-
product.jdbc.url=jdbc:mysql://localhost:3306/spring_jpa_product?createDatabaseIfNotExist=true
5-
jdbc.user=tutorialuser
6-
jdbc.pass=tutorialmy5ql
2+
jdbc.driverClassName=org.h2.Driver
3+
user.jdbc.url=jdbc:h2:mem:spring_jpa_user;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS SPRING_JPA_USER
4+
product.jdbc.url=jdbc:h2:mem:spring_jpa_product;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS SPRING_JPA_PRODUCT
5+
jdbc.user=sa
6+
jdbc.pass=
77

88
# hibernate.X
9-
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
9+
hibernate.dialect=org.hibernate.dialect.H2Dialect
1010
hibernate.show_sql=false
1111
hibernate.hbm2ddl.auto=create-drop
1212
hibernate.cache.use_second_level_cache=false

‎persistence-modules/spring-jpa/src/main/resources/persistence-student-h2.properties‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
jdbc.driverClassName=org.h2.Driver
33
jdbc.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
44
jdbc.user=sa
5-
# jdbc.pass=
5+
jdbc.pass=
66

77
# hibernate.X
88
hibernate.dialect=org.hibernate.dialect.H2Dialect

‎persistence-modules/spring-jpa/src/main/resources/persistence.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd"
88
>
99

10-
<context:property-placeholder location="classpath:persistence-mysql.properties"/>
10+
<context:property-placeholder location="classpath:persistence-h2.properties"/>
1111

1212
<bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
1313
<property name="dataSource" ref="dataSource"/>

‎persistence-modules/spring-jpa/src/test/java/org/baeldung/dsrouting/DataSourceRoutingIntegrationTest.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
import org.junit.runner.RunWith;
1010
import org.springframework.beans.factory.annotation.Autowired;
1111
import org.springframework.jdbc.core.JdbcTemplate;
12+
import org.springframework.test.annotation.DirtiesContext;
1213
import org.springframework.test.context.ContextConfiguration;
1314
import org.springframework.test.context.junit4.SpringRunner;
1415

1516
@RunWith(SpringRunner.class)
1617
@ContextConfiguration(classes = DataSourceRoutingTestConfiguration.class)
18+
@DirtiesContext
1719
public class DataSourceRoutingIntegrationTest {
1820

1921
@Autowired

‎persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/deletion/config/PersistenceJPAConfigDeletion.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ public PersistenceJPAConfigDeletion() {
1010

1111
@Override
1212
protected String[] getPackagesToScan() {
13-
return new String[] { "org.baeldung.persistence.deletion.model" };
13+
return new String[] { "org.baeldung.persistence.deletion.model", "org.baeldung.persistence.model" };
1414
}
1515
}

‎persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/repository/AdvancedTaggingIntegrationTest.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.baeldung.inmemory.persistence.model.Student;
1212
import org.junit.Test;
1313
import org.junit.runner.RunWith;
14+
import org.springframework.test.annotation.DirtiesContext;
1415
import org.springframework.test.context.ContextConfiguration;
1516
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
1617
import org.springframework.test.context.support.AnnotationConfigContextLoader;
@@ -26,6 +27,7 @@
2627
@RunWith(SpringJUnit4ClassRunner.class)
2728
@ContextConfiguration(classes = { StudentJpaConfig.class }, loader = AnnotationConfigContextLoader.class)
2829
@Transactional
30+
@DirtiesContext
2931
public class AdvancedTaggingIntegrationTest {
3032
@Resource
3133
private StudentRepository studentRepository;

0 commit comments

Comments
 (0)