[BAEL-7621] - Fixed integration test of spring-hibernate-5 module by introducing H2 database
This commit is contained in:
parent
be42e569d6
commit
08796cb9b0
|
@ -3,13 +3,15 @@ package com.baeldung.hibernate.manytomany.model;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.JoinTable;
|
|
||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.JoinTable;
|
||||||
import javax.persistence.ManyToMany;
|
import javax.persistence.ManyToMany;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@ -18,7 +20,7 @@ import javax.persistence.Table;
|
||||||
public class Employee implements Serializable {
|
public class Employee implements Serializable {
|
||||||
@Id
|
@Id
|
||||||
@Column(name = "employee_id")
|
@Column(name = "employee_id")
|
||||||
@GeneratedValue
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long employeeId;
|
private Long employeeId;
|
||||||
|
|
||||||
@Column(name = "first_name")
|
@Column(name = "first_name")
|
||||||
|
|
|
@ -50,6 +50,8 @@ public class HibernateSearchConfig {
|
||||||
final BasicDataSource dataSource = new BasicDataSource();
|
final BasicDataSource dataSource = new BasicDataSource();
|
||||||
dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName")));
|
dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName")));
|
||||||
dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url")));
|
dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url")));
|
||||||
|
dataSource.setUsername(env.getProperty("jdbc.user"));
|
||||||
|
dataSource.setPassword(env.getProperty("jdbc.pass"));
|
||||||
|
|
||||||
return dataSource;
|
return dataSource;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
@PropertySource({ "classpath:persistence-mysql.properties" })
|
@PropertySource({ "classpath:persistence-h2.properties" })
|
||||||
@ComponentScan({ "com.baeldung.hibernate.manytomany" })
|
@ComponentScan({ "com.baeldung.hibernate.manytomany" })
|
||||||
public class PersistenceConfig {
|
public class PersistenceConfig {
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public class PersistenceConfig {
|
||||||
|
|
||||||
private final Properties hibernateProperties() {
|
private final Properties hibernateProperties() {
|
||||||
final Properties hibernateProperties = new Properties();
|
final Properties hibernateProperties = new Properties();
|
||||||
//hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
|
hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
|
||||||
hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect"));
|
hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect"));
|
||||||
hibernateProperties.setProperty("hibernate.show_sql", "true");
|
hibernateProperties.setProperty("hibernate.show_sql", "true");
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ import java.util.Properties;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
@PropertySource({ "classpath:persistence-mysql.properties" })
|
@PropertySource({ "classpath:persistence-h2.properties" })
|
||||||
@ComponentScan({ "com.baeldung.persistence" })
|
@ComponentScan({ "com.baeldung.persistence" })
|
||||||
public class PersistenceConfig {
|
public class PersistenceConfig {
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ jdbc.driverClassName=org.h2.Driver
|
||||||
jdbc.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
|
jdbc.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
|
||||||
jdbc.eventGeneratedId=sa
|
jdbc.eventGeneratedId=sa
|
||||||
jdbc.user=sa
|
jdbc.user=sa
|
||||||
jdbc.pass=sa
|
jdbc.pass=
|
||||||
|
|
||||||
# hibernate.X
|
# hibernate.X
|
||||||
hibernate.dialect=org.hibernate.dialect.H2Dialect
|
hibernate.dialect=org.hibernate.dialect.H2Dialect
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE hibernate-configuration PUBLIC
|
||||||
|
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
|
||||||
|
"http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||||
|
<hibernate-configuration>
|
||||||
|
<session-factory>
|
||||||
|
<property name="hibernate.connection.driver_class">org.h2.Driver</property>
|
||||||
|
<property name="hibernate.connection.password"></property>
|
||||||
|
<property name="hibernate.connection.url">jdbc:h2:mem:spring_hibernate_many_to_many</property>
|
||||||
|
<property name="hibernate.connection.username">sa</property>
|
||||||
|
<property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
|
||||||
|
<property name="hibernate.current_session_context_class">thread</property>
|
||||||
|
<property name="hibernate.show_sql">true</property>
|
||||||
|
<property name="hibernate.hbm2ddl.auto">create-drop</property>
|
||||||
|
</session-factory>
|
||||||
|
</hibernate-configuration>
|
Loading…
Reference in New Issue