Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
HHH-12051 - Filter dirty but non-updatable atributes
- Loading branch information
1 parent
1965a9b
commit 280474e
Showing
2 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...st/java/org/hibernate/test/bytecode/enhancement/dirty/DirtyTrackingNonUpdateableTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.test.bytecode.enhancement.dirty; | ||
|
||
import org.hibernate.testing.TestForIssue; | ||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; | ||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
import javax.persistence.Version; | ||
|
||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; | ||
|
||
/** | ||
* @author Luis Barreiro | ||
*/ | ||
@TestForIssue( jiraKey = "HHH-12051" ) | ||
@RunWith( BytecodeEnhancerRunner.class ) | ||
public class DirtyTrackingNonUpdateableTest extends BaseCoreFunctionalTestCase { | ||
|
||
@Override | ||
public Class<?>[] getAnnotatedClasses() { | ||
return new Class<?>[]{Thing.class}; | ||
} | ||
|
||
@Test | ||
public void test() { | ||
doInJPA( this::sessionFactory, entityManager -> { | ||
Thing thing = new Thing(); | ||
entityManager.persist( thing ); | ||
|
||
entityManager | ||
.createQuery( "update thing set special = :s, version = version + 1" ) | ||
.setParameter( "s", "new" ) | ||
.executeUpdate(); | ||
|
||
thing.special = "If I'm flush to the DB you get an OptimisticLockException"; | ||
} ); | ||
} | ||
|
||
// --- // | ||
|
||
@Entity( name = "thing" ) | ||
@Table( name = "THING_ENTITY" ) | ||
public class Thing { | ||
|
||
@Id | ||
@GeneratedValue( strategy = GenerationType.IDENTITY ) | ||
long id; | ||
|
||
@Version | ||
long version; | ||
|
||
@Column( updatable = false ) | ||
String special; | ||
} | ||
} |