Skip to content

Commit b31327b

Browse files
Add test for hibernate id generator
1 parent 243b1dc commit b31327b

File tree

3 files changed

+87
-21
lines changed

3 files changed

+87
-21
lines changed

tests/src/org.hibernate.orm/hibernate-core/6.1.1.Final/src/test/java/org/hibernate/orm/HibernateOrmTest.java

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright and related rights waived via CC0
3+
*
4+
* You should have received a copy of the CC0 legalcode along with this
5+
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
6+
*/
7+
package org.hibernate.orm;
8+
9+
import jakarta.persistence.Column;
10+
import jakarta.persistence.Entity;
11+
import jakarta.persistence.GeneratedValue;
12+
import jakarta.persistence.Id;
13+
import jakarta.persistence.Table;
14+
import org.hibernate.annotations.GenericGenerator;
15+
16+
17+
@Entity
18+
@Table(name = "USER")
19+
public class User {
20+
21+
@Id
22+
@GeneratedValue(generator = "uuid")
23+
@GenericGenerator(name = "uuid", strategy = "uuid")
24+
@Column(columnDefinition = "CHAR(32)")
25+
private String id;
26+
27+
private String username;
28+
29+
public String getId() {
30+
return id;
31+
}
32+
33+
public void setId(String id) {
34+
this.id = id;
35+
}
36+
37+
public String getUsername() {
38+
return username;
39+
}
40+
41+
public void setUsername(String username) {
42+
this.username = username;
43+
}
44+
}

tests/src/org.hibernate.orm/hibernate-core/6.1.1.Final/src/test/resources/META-INF/native-image/dto-runtime-hints/reflect-config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,10 @@
1313
"name": "org.hibernate.orm.Item",
1414
"allDeclaredFields": true,
1515
"allDeclaredConstructors": true
16+
},
17+
{
18+
"name": "org.hibernate.orm.User",
19+
"allDeclaredFields": true,
20+
"allDeclaredConstructors": true
1621
}
1722
]

0 commit comments

Comments
 (0)