File tree Expand file tree Collapse file tree
persistence-modules/spring-hibernate-5/src
hibernate/manytomany/model Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33import java .io .Serializable ;
44import java .util .HashSet ;
55import java .util .Set ;
6+
67import javax .persistence .CascadeType ;
78import javax .persistence .Column ;
89import javax .persistence .Entity ;
910import javax .persistence .GeneratedValue ;
11+ import javax .persistence .GenerationType ;
1012import javax .persistence .Id ;
11- import javax .persistence .JoinTable ;
1213import javax .persistence .JoinColumn ;
14+ import javax .persistence .JoinTable ;
1315import javax .persistence .ManyToMany ;
1416import javax .persistence .Table ;
1517
1820public class Employee implements Serializable {
1921 @ Id
2022 @ Column (name = "employee_id" )
21- @ GeneratedValue
23+ @ GeneratedValue ( strategy = GenerationType . IDENTITY )
2224 private Long employeeId ;
2325
2426 @ Column (name = "first_name" )
Original file line number Diff line number Diff line change @@ -50,6 +50,8 @@ public DataSource dataSource() {
5050 final BasicDataSource dataSource = new BasicDataSource ();
5151 dataSource .setDriverClassName (Preconditions .checkNotNull (env .getProperty ("jdbc.driverClassName" )));
5252 dataSource .setUrl (Preconditions .checkNotNull (env .getProperty ("jdbc.url" )));
53+ dataSource .setUsername (env .getProperty ("jdbc.user" ));
54+ dataSource .setPassword (env .getProperty ("jdbc.pass" ));
5355
5456 return dataSource ;
5557 }
Original file line number Diff line number Diff line change 1919
2020@ Configuration
2121@ EnableTransactionManagement
22- @ PropertySource ({ "classpath:persistence-mysql .properties" })
22+ @ PropertySource ({ "classpath:persistence-h2 .properties" })
2323@ ComponentScan ({ "com.baeldung.hibernate.manytomany" })
2424public class PersistenceConfig {
2525
@@ -61,7 +61,7 @@ public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
6161
6262 private final Properties hibernateProperties () {
6363 final Properties hibernateProperties = new Properties ();
64- // hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
64+ hibernateProperties .setProperty ("hibernate.hbm2ddl.auto" , env .getProperty ("hibernate.hbm2ddl.auto" ));
6565 hibernateProperties .setProperty ("hibernate.dialect" , env .getProperty ("hibernate.dialect" ));
6666 hibernateProperties .setProperty ("hibernate.show_sql" , "true" );
6767
Original file line number Diff line number Diff line change 2121
2222@ Configuration
2323@ EnableTransactionManagement
24- @ PropertySource ({ "classpath:persistence-mysql .properties" })
24+ @ PropertySource ({ "classpath:persistence-h2 .properties" })
2525@ ComponentScan ({ "com.baeldung.persistence" })
2626public class PersistenceConfig {
2727
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ jdbc.driverClassName=org.h2.Driver
33jdbc.url =jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
44jdbc.eventGeneratedId =sa
55jdbc.user =sa
6- jdbc.pass =sa
6+ jdbc.pass =
77
88# hibernate.X
99hibernate.dialect =org.hibernate.dialect.H2Dialect
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <!DOCTYPE hibernate-configuration PUBLIC
3+ "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
4+ "http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
5+ <hibernate-configuration >
6+ <session-factory >
7+ <property name =" hibernate.connection.driver_class" >org.h2.Driver</property >
8+ <property name =" hibernate.connection.password" ></property >
9+ <property name =" hibernate.connection.url" >jdbc:h2:mem:spring_hibernate_many_to_many</property >
10+ <property name =" hibernate.connection.username" >sa</property >
11+ <property name =" hibernate.dialect" >org.hibernate.dialect.H2Dialect</property >
12+ <property name =" hibernate.current_session_context_class" >thread</property >
13+ <property name =" hibernate.show_sql" >true</property >
14+ <property name =" hibernate.hbm2ddl.auto" >create-drop</property >
15+ </session-factory >
16+ </hibernate-configuration >
You can’t perform that action at this time.
0 commit comments