From 6bb1900495b25aa2d14faa98c2d00b0b24d1f37e Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Wed, 19 May 2021 17:08:08 -0700 Subject: [PATCH] HHH-14616 : Add test case with default hibernate.globally_quoted_identifiers (=false) and version column quoted --- .../OptimisticLockWithQuotedVersionTest.java | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/optlock/OptimisticLockWithQuotedVersionTest.java diff --git a/hibernate-core/src/test/java/org/hibernate/test/optlock/OptimisticLockWithQuotedVersionTest.java b/hibernate-core/src/test/java/org/hibernate/test/optlock/OptimisticLockWithQuotedVersionTest.java new file mode 100644 index 0000000000..6d1bb39a87 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/optlock/OptimisticLockWithQuotedVersionTest.java @@ -0,0 +1,89 @@ +package org.hibernate.test.optlock; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.LockModeType; +import javax.persistence.Version; + +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Configuration; + +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class OptimisticLockWithQuotedVersionTest extends BaseCoreFunctionalTestCase { + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] { Person.class }; + } + + @Before + public void setUp() { + inTransaction( + session -> { + Person person = new Person( "1", "Fabiana" ); + session.persist( person ); + } + ); + } + + @After + public void tearDown() { + inTransaction( + session -> { + session.createQuery( "delete from Person" ).executeUpdate(); + } + ); + } + + @Test + public void testHqlQueryWithOptimisticLock() { + inTransaction( + session -> { + session.createQuery( "from Person e", Person.class ) + .setLockMode( LockModeType.OPTIMISTIC ) + .getResultList().get( 0 ); + } + ); + } + + @Entity(name = "Person") + public static class Person { + @Id + private String id; + + @Version + @Column(name = "`version`") + private long version; + + private String name; + + public Person() { + } + + public Person(String id, String name) { + this.id = id; + this.name = name; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } +}