Skip to content

Commit 6818e49

Browse files
committed
HHH-14985 H2Dialect does not work properly with h2 2.0.202 on inserts
1 parent fb8186d commit 6818e49

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/identity/H2IdentityColumnSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ public String getIdentitySelectString(String table, String column, int type) {
2828

2929
@Override
3030
public String getIdentityInsertString() {
31-
return "null";
31+
return "default";
3232
}
3333
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.orm.test.dialect;
8+
9+
import java.util.List;
10+
11+
import jakarta.persistence.Entity;
12+
import jakarta.persistence.GeneratedValue;
13+
import jakarta.persistence.GenerationType;
14+
import jakarta.persistence.Id;
15+
16+
import org.hibernate.dialect.H2Dialect;
17+
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
18+
19+
import org.hibernate.testing.RequiresDialect;
20+
import org.hibernate.testing.TestForIssue;
21+
import org.junit.Test;
22+
23+
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
24+
import static org.junit.Assert.assertEquals;
25+
26+
@RequiresDialect(H2Dialect.class)
27+
public class H2DialectTestCase extends BaseEntityManagerFunctionalTestCase {
28+
29+
@Override
30+
protected Class<?>[] getAnnotatedClasses() {
31+
return new Class<?>[] { SimpleEntity.class };
32+
}
33+
34+
@TestForIssue(jiraKey = "HHH-14985")
35+
@Test
36+
public void testInsertWithDefault() {
37+
doInJPA( this::entityManagerFactory, entityManager -> {
38+
final SimpleEntity simpleEntity = new SimpleEntity( "Entity1" );
39+
entityManager.persist( simpleEntity );
40+
} );
41+
doInJPA( this::entityManagerFactory, entityManager -> {
42+
List<SimpleEntity> results = entityManager.createQuery( "FROM SimpleEntity", SimpleEntity.class )
43+
.getResultList();
44+
assertEquals( 1, results.size() );
45+
} );
46+
}
47+
48+
@Entity(name = "SimpleEntity")
49+
public static class SimpleEntity {
50+
@Id
51+
@GeneratedValue(strategy = GenerationType.IDENTITY)
52+
private Integer id;
53+
private String name;
54+
55+
public SimpleEntity() {
56+
57+
}
58+
59+
public SimpleEntity(String name) {
60+
this.name = name;
61+
}
62+
63+
public Integer getId() {
64+
return id;
65+
}
66+
67+
public void setId(Integer id) {
68+
this.id = id;
69+
}
70+
71+
public String getName() {
72+
return name;
73+
}
74+
75+
public void setName(String name) {
76+
this.name = name;
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)