File tree Expand file tree Collapse file tree 3 files changed +90
-5
lines changed
orm/hibernate-orm-6/src/test/java/org/hibernate/bugs Expand file tree Collapse file tree 3 files changed +90
-5
lines changed Original file line number Diff line number Diff line change 1+ package org .hibernate .bugs ;
2+
3+ import jakarta .persistence .EmbeddedId ;
4+ import jakarta .persistence .Entity ;
5+
6+ @ Entity
7+ public class MyEntity {
8+
9+ // The name of this property must be (alphabetically) before the name of "data" to trigger the bug.
10+ // Yes, it's weird.
11+ @ EmbeddedId
12+ private MyEntityId anId ;
13+
14+ private String data ;
15+
16+ public MyEntityId getAnId () {
17+ return anId ;
18+ }
19+
20+ public void setAnId (MyEntityId anId ) {
21+ this .anId = anId ;
22+ }
23+
24+ public String getData () {
25+ return data ;
26+ }
27+
28+ public void setData (String data ) {
29+ this .data = data ;
30+ }
31+ }
Original file line number Diff line number Diff line change 1+ package org .hibernate .bugs ;
2+
3+ import java .util .Objects ;
4+
5+ import jakarta .persistence .Embeddable ;
6+
7+ @ Embeddable
8+ public class MyEntityId {
9+ private long val ;
10+
11+ protected MyEntityId () {
12+ }
13+
14+ public MyEntityId (long val ) {
15+ this .val = val ;
16+ }
17+
18+ public long getVal () {
19+ return val ;
20+ }
21+
22+ public void setVal (long val ) {
23+ this .val = val ;
24+ }
25+
26+ @ Override
27+ public boolean equals (Object o ) {
28+ if ( o == null || getClass () != o .getClass () ) {
29+ return false ;
30+ }
31+ MyEntityId id = (MyEntityId ) o ;
32+ return val == id .val ;
33+ }
34+
35+ @ Override
36+ public int hashCode () {
37+ return Objects .hashCode ( val );
38+ }
39+ }
Original file line number Diff line number Diff line change 1515 */
1616package org .hibernate .bugs ;
1717
18+ import static org .assertj .core .api .Assertions .assertThat ;
19+
1820import org .hibernate .cfg .AvailableSettings ;
1921
2022import org .hibernate .testing .bytecode .enhancement .CustomEnhancementContext ;
3436 */
3537@ DomainModel (
3638 annotatedClasses = {
37- // Add your entities here, e.g.:
38- // Foo.class,
39- // Bar.class
39+ MyEntity .class
4040 }
4141)
4242@ ServiceRegistry (
@@ -67,9 +67,24 @@ class QuarkusLikeORMUnitTestCase {
6767
6868 // Add your tests, using standard JUnit.
6969 @ Test
70- void hhh123Test (SessionFactoryScope scope ) throws Exception {
70+ void hhh123Test (SessionFactoryScope scope ) {
71+ var entity = new MyEntity ();
72+ entity .setAnId ( new MyEntityId ( 1L ) );
73+ entity .setData ( "initial" );
74+ var entityAfterFirstMerge = scope .fromTransaction ( session -> {
75+ return session .merge ( entity );
76+ } );
77+
78+ // This is unnecessary, but should be harmless... Unfortunately it causes dirty checking to misbehave.
79+ entityAfterFirstMerge .setAnId ( new MyEntityId ( 1L ) );
80+
81+ scope .inTransaction ( session -> {
82+ entityAfterFirstMerge .setData ( "updated" );
83+ session .merge ( entityAfterFirstMerge );
84+ } );
7185 scope .inTransaction ( session -> {
72- // Do stuff...
86+ var entityFromDb = session .find ( MyEntity .class , new MyEntityId ( 1L ) );
87+ assertThat ( entityFromDb .getData () ).isEqualTo ( "updated" );
7388 } );
7489 }
7590}
You can’t perform that action at this time.
0 commit comments