Skip to content

Commit 34a8f06

Browse files
committed
HHH-15045 + HHH-15235 onFlushDirty() invoked on parent entity in a @OnetoOne relationship when no table columns are changed - PropertyAccessException on merging Bidirectional OneToOne with EmbeddedId - Reverted HHH-14216
1 parent b63376b commit 34a8f06

File tree

3 files changed

+17
-32
lines changed

3 files changed

+17
-32
lines changed

hibernate-core/src/main/java/org/hibernate/type/EntityType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ public boolean isEqual(Object x, Object y, SessionFactoryImplementor factory) {
385385
/**
386386
* Resolve an identifier or unique key value
387387
*/
388-
private Object resolve(Object value, SharedSessionContractImplementor session, Object owner) {
388+
protected Object resolve(Object value, SharedSessionContractImplementor session, Object owner) {
389389
if ( value != null && !isNull( owner, session ) ) {
390390
if ( isReferenceToPrimaryKey() ) {
391391
return resolveIdentifier( value, session, null );

hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,12 @@ public boolean isOneToOne() {
106106

107107
@Override
108108
public boolean isDirty(Object old, Object current, SharedSessionContractImplementor session) {
109-
if ( isSame( old, current ) ) {
110-
return false;
111-
}
112-
113-
return getIdentifierType( session )
114-
.isDirty( getIdentifier( old, session ), getIdentifier( current, session ), session );
109+
return false;
115110
}
116111

117112
@Override
118113
public boolean isDirty(Object old, Object current, boolean[] checkable, SharedSessionContractImplementor session) {
119-
return isDirty(old, current, session);
114+
return false;
120115
}
121116

122117
@Override
@@ -141,37 +136,25 @@ public boolean useLHSPrimaryKey() {
141136

142137
@Override
143138
public Serializable disassemble(Object value, SharedSessionContractImplementor session, Object owner) throws HibernateException {
144-
if (value == null) {
145-
return null;
146-
}
147-
148-
Object id = ForeignKeys.getEntityIdentifierIfNotUnsaved( getAssociatedEntityName(), value, session );
149-
150-
if ( id == null ) {
151-
throw new AssertionFailure(
152-
"cannot cache a reference to an object with a null id: " +
153-
getAssociatedEntityName()
154-
);
155-
}
156-
157-
return getIdentifierType( session ).disassemble( id, session, owner );
139+
return null;
158140
}
159141

160142
@Override
161143
public Object assemble(Serializable oid, SharedSessionContractImplementor session, Object owner) throws HibernateException {
162-
163-
//the owner of the association is not the owner of the id
164-
Object id = getIdentifierType( session ).assemble( oid, session, null );
165-
166-
if ( id == null ) {
167-
return null;
168-
}
169-
170-
return resolveIdentifier( id, session );
144+
//this should be a call to resolve(), not resolveIdentifier(),
145+
//'cos it might be a property-ref, and we did not cache the
146+
//referenced value
147+
return resolve( session.getContextEntityIdentifier(owner), session, owner );
171148
}
172149

150+
/**
151+
* We don't need to dirty check one-to-one because of how
152+
* assemble/disassemble is implemented and because a one-to-one
153+
* association is never dirty
154+
*/
173155
@Override
174156
public boolean isAlwaysDirtyChecked() {
175-
return true;
157+
//TODO: this is kinda inconsistent with CollectionType
158+
return false;
176159
}
177160
}

hibernate-core/src/test/java/org/hibernate/orm/test/onetoone/cache/OneToOneCacheTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.hibernate.stat.spi.StatisticsImplementor;
1111

1212
import org.hibernate.testing.orm.junit.DomainModel;
13+
import org.hibernate.testing.orm.junit.FailureExpected;
1314
import org.hibernate.testing.orm.junit.ServiceRegistry;
1415
import org.hibernate.testing.orm.junit.SessionFactory;
1516
import org.hibernate.testing.orm.junit.SessionFactoryScope;
@@ -120,6 +121,7 @@ private <TPerson extends Person> List<TPerson> getPersons(
120121
}
121122

122123
@Test
124+
@FailureExpected( jiraKey = "HHH-14216", reason = "The changes introduces by HHH-14216 have been reverted see https://github.com/hibernate/hibernate-orm/pull/5061 discussion")
123125
public void OneToOneCacheByForeignKey(SessionFactoryScope scope) throws Exception {
124126
OneToOneTest( PersonByFK.class, DetailsByFK.class, scope );
125127
}

0 commit comments

Comments
 (0)