|
| 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