-
Notifications
You must be signed in to change notification settings - Fork 3.6k
HHH-15045 + HHH-15235 #5331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
HHH-15045 + HHH-15235 #5331
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
85 changes: 85 additions & 0 deletions
85
hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/EmbeddedIdTest.java
This file contains hidden or 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,85 @@ | ||
/* | ||
* 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.annotations.onetoone; | ||
|
||
import java.io.Serializable; | ||
|
||
import org.hibernate.testing.TestForIssue; | ||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; | ||
|
||
import javax.persistence.CascadeType; | ||
import javax.persistence.Embeddable; | ||
import javax.persistence.EmbeddedId; | ||
import javax.persistence.Entity; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.OneToOne; | ||
import javax.persistence.Table; | ||
|
||
import org.junit.Test; | ||
|
||
@TestForIssue(jiraKey = "HHH-15235") | ||
public class EmbeddedIdTest extends BaseCoreFunctionalTestCase { | ||
|
||
@Override | ||
protected Class<?>[] getAnnotatedClasses() { | ||
return new Class[] { Bar.class, Foo.class }; | ||
} | ||
|
||
@Test | ||
public void testMerge() { | ||
inTransaction( | ||
session -> { | ||
FooId fooId = new FooId(); | ||
fooId.id = "foo"; | ||
Foo foo = new Foo(); | ||
foo.id = fooId; | ||
Bar bar = new Bar(); | ||
BarId barId = new BarId(); | ||
barId.id = 1l; | ||
bar.id = barId; | ||
foo.bar = bar; | ||
bar.foo = foo; | ||
session.merge( foo ); | ||
} | ||
); | ||
} | ||
|
||
@Embeddable | ||
public static class BarId implements Serializable { | ||
private Long id; | ||
} | ||
|
||
@Embeddable | ||
public static class FooId implements Serializable { | ||
private String id; | ||
} | ||
|
||
@Entity(name = "Bar") | ||
@Table(name = "BAR_TABLE") | ||
public static class Bar { | ||
@EmbeddedId | ||
private BarId id; | ||
|
||
private String name; | ||
|
||
@OneToOne(mappedBy = "bar") | ||
private Foo foo; | ||
} | ||
|
||
@Entity(name = "Foo") | ||
@Table(name = "FOO_TABLE") | ||
public static class Foo { | ||
@EmbeddedId | ||
private FooId id; | ||
|
||
private String name; | ||
|
||
@OneToOne(cascade = CascadeType.ALL) | ||
@JoinColumn(name = "bar_id") | ||
private Bar bar; | ||
} | ||
} |
This file contains hidden or 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
109 changes: 109 additions & 0 deletions
109
hibernate-core/src/test/java/org/hibernate/test/onetoone/flush/DirtyFlushTest.java
This file contains hidden or 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,109 @@ | ||
/* | ||
* 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.onetoone.flush; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
import javax.persistence.OneToOne; | ||
import javax.persistence.Table; | ||
import javax.persistence.Version; | ||
|
||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; | ||
|
||
import org.hibernate.testing.TestForIssue; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.hibernate.testing.orm.transaction.TransactionUtil.inTransaction; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
@TestForIssue(jiraKey = "HHH-15045") | ||
public class DirtyFlushTest extends BaseEntityManagerFunctionalTestCase { | ||
|
||
@Override | ||
protected Class<?>[] getAnnotatedClasses() { | ||
return new Class[] { User.class, Profile.class }; | ||
} | ||
|
||
@Before | ||
public void setUp() { | ||
inTransaction( getOrCreateEntityManager(), em -> { | ||
final User user = new User(); | ||
user.id = 1; | ||
user.version = 1; | ||
|
||
final Profile profile = new Profile(); | ||
profile.id = 1; | ||
profile.version = 1; | ||
|
||
em.persist( user ); | ||
em.persist( profile ); | ||
} ); | ||
} | ||
|
||
@Test | ||
public void testDirtyFlushNotHappened() { | ||
inTransaction( getOrCreateEntityManager(), em -> { | ||
final User user = em.find( User.class, 1 ); | ||
assertEquals( 1, user.version ); | ||
|
||
final Profile profile = em.find( Profile.class, 1 ); | ||
assertEquals( 1, profile.version ); | ||
|
||
profile.user = user; | ||
user.profile = profile; | ||
|
||
em.persist( profile ); | ||
} ); | ||
|
||
inTransaction( getOrCreateEntityManager(), em -> { | ||
final Profile profile = em.find( Profile.class, 1 ); | ||
assertEquals( 2, profile.version ); | ||
|
||
final User user = em.find( User.class, 1 ); | ||
assertEquals( | ||
"without fixing, the version will be bumped due to erroneous dirty flushing", | ||
1, | ||
user.version | ||
); | ||
} ); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
inTransaction( getOrCreateEntityManager(), em -> { | ||
em.createQuery( "delete from Profile" ).executeUpdate(); | ||
em.createQuery( "delete from User" ).executeUpdate(); | ||
} ); | ||
} | ||
|
||
@Entity(name = "User") | ||
@Table(name = "USER_TABLE") | ||
public static class User { | ||
@Id | ||
int id; | ||
|
||
@Version | ||
int version; | ||
|
||
@OneToOne(mappedBy = "user") | ||
Profile profile; | ||
} | ||
|
||
@Entity(name = "Profile") | ||
@Table(name = "PROFILE_TABLE") | ||
public static class Profile { | ||
@Id | ||
int id; | ||
|
||
@Version | ||
int version; | ||
@OneToOne // internally Hibernate will use `@ManyToOne` for this field | ||
User user; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this being changed? We don't typically change existing release notes
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the PR has been applied to 5.5.0.Alpha1 but we forgot to close the related Jira so I closed it and amended the release notes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, thanks!