@@ -35,16 +35,7 @@ void jpaBootstrap() {
3535 @ Test
3636 void hibernateBootstrap () {
3737
38- Configuration config = new Configuration ();
39-
40- config .setProperty ("hibernate.connection.driver_class" , "org.h2.Driver" );
41- config .setProperty ("hibernate.connection.url" , "jdbc:h2:mem:test" );
42- config .setProperty ("hibernate.connection.username" , "" );
43- config .setProperty ("hibernate.connection.password" , "" );
44- config .setProperty ("hibernate.dialect" , "org.hibernate.dialect.H2Dialect" );
45- config .setProperty ("hibernate.hbm2ddl.auto" , "create-drop" );
46-
47- config .addAnnotatedClass (Event .class );
38+ Configuration config = h2Config (Event .class );
4839
4940 SessionFactory sessionFactory = config .buildSessionFactory ();
5041 Session session = sessionFactory .openSession ();
@@ -59,17 +50,7 @@ void hibernateBootstrap() {
5950 @ Test
6051 void relations () {
6152
62- Configuration config = new Configuration ();
63-
64- config .setProperty ("hibernate.connection.driver_class" , "org.h2.Driver" );
65- config .setProperty ("hibernate.connection.url" , "jdbc:h2:mem:test" );
66- config .setProperty ("hibernate.connection.username" , "" );
67- config .setProperty ("hibernate.connection.password" , "" );
68- config .setProperty ("hibernate.dialect" , "org.hibernate.dialect.H2Dialect" );
69- config .setProperty ("hibernate.hbm2ddl.auto" , "create-drop" );
70-
71- config .addAnnotatedClass (Cart .class );
72- config .addAnnotatedClass (Item .class );
53+ Configuration config = h2Config (Cart .class , Item .class );
7354
7455 SessionFactory sessionFactory = config .buildSessionFactory ();
7556 Session session = sessionFactory .openSession ();
@@ -87,4 +68,40 @@ void relations() {
8768 session .close ();
8869 sessionFactory .close ();
8970 }
71+
72+ @ Test
73+ void idGenerator () {
74+
75+ Configuration config = h2Config (User .class );
76+
77+ SessionFactory sessionFactory = config .buildSessionFactory ();
78+ Session session = sessionFactory .openSession ();
79+
80+ User user = new User ();
81+ user .setUsername ("u1" );
82+
83+ session .persist (user );
84+
85+ User load = session .byId (User .class ).load (user .getId ());
86+
87+ session .close ();
88+ sessionFactory .close ();
89+ }
90+
91+ private static Configuration h2Config (Class <?>... entities ) {
92+
93+ Configuration config = new Configuration ();
94+ config .setProperty ("hibernate.connection.driver_class" , "org.h2.Driver" );
95+ config .setProperty ("hibernate.connection.url" , "jdbc:h2:mem:test" );
96+ config .setProperty ("hibernate.connection.username" , "" );
97+ config .setProperty ("hibernate.connection.password" , "" );
98+ config .setProperty ("hibernate.dialect" , "org.hibernate.dialect.H2Dialect" );
99+ config .setProperty ("hibernate.hbm2ddl.auto" , "create-drop" );
100+
101+ for (Class <?> type : entities ) {
102+ config .addAnnotatedClass (type );
103+ }
104+
105+ return config ;
106+ }
90107}
0 commit comments