Skip to content

Commit e1d7710

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 a090be9 commit e1d7710

File tree

3 files changed

+18
-33
lines changed

3 files changed

+18
-33
lines changed

changelog.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ https://hibernate.atlassian.net/projects/HHH/versions/31844
500500
* [HHH-14257] - An Entity A with a map collection having as index an Embeddable with a an association to the Entity A fails with a NPE
501501
* [HHH-14251] - Invalid SQL for @Embedded UPDATE
502502
* [HHH-14249] - MultiLineImport fails when script contains blank spaces or tabs at the end of the last sql statement
503-
503+
* [HHH-14216] - Second-level cache doesn't support @OneToOne
504504

505505
Changes in 5.4.14.Final (April 6, 2020)
506506
------------------------------------------------------------------------------------------------------------------------

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

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,12 @@ public boolean isOneToOne() {
152152

153153
@Override
154154
public boolean isDirty(Object old, Object current, SharedSessionContractImplementor session) {
155-
if ( isSame( old, current ) ) {
156-
return false;
157-
}
158-
159-
Object oldid = getIdentifier( old, session );
160-
Object newid = getIdentifier( current, session );
161-
162-
return getIdentifierType( session ).isDirty( oldid, newid, session );
155+
return false;
163156
}
164157

165158
@Override
166159
public boolean isDirty(Object old, Object current, boolean[] checkable, SharedSessionContractImplementor session) {
167-
return isDirty(old, current, session);
160+
return false;
168161
}
169162

170163
@Override
@@ -203,36 +196,25 @@ public boolean useLHSPrimaryKey() {
203196

204197
@Override
205198
public Serializable disassemble(Object value, SharedSessionContractImplementor session, Object owner) throws HibernateException {
206-
if (value == null) {
207-
return null;
208-
}
209-
210-
Object id = ForeignKeys.getEntityIdentifierIfNotUnsaved( getAssociatedEntityName(), value, session );
211-
212-
if ( id == null ) {
213-
throw new AssertionFailure(
214-
"cannot cache a reference to an object with a null id: " +
215-
getAssociatedEntityName()
216-
);
217-
}
218-
219-
return getIdentifierType( session ).disassemble( id, session, owner );
199+
return null;
220200
}
221201

222202
@Override
223203
public Object assemble(Serializable oid, SharedSessionContractImplementor session, Object owner) throws HibernateException {
224-
//the owner of the association is not the owner of the id
225-
Serializable id = ( Serializable ) getIdentifierType( session ).assemble( oid, session, null );
226-
227-
if ( id == null ) {
228-
return null;
229-
}
230-
231-
return resolveIdentifier( id, session );
204+
//this should be a call to resolve(), not resolveIdentifier(),
205+
//'cos it might be a property-ref, and we did not cache the
206+
//referenced value
207+
return resolve( session.getContextEntityIdentifier(owner), session, owner );
232208
}
233209

210+
/**
211+
* We don't need to dirty check one-to-one because of how
212+
* assemble/disassemble is implemented and because a one-to-one
213+
* association is never dirty
214+
*/
234215
@Override
235216
public boolean isAlwaysDirtyChecked() {
236-
return true;
217+
//TODO: this is kinda inconsistent with CollectionType
218+
return false;
237219
}
238220
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import org.hibernate.cfg.Configuration;
1515
import org.hibernate.engine.spi.SessionFactoryImplementor;
1616
import org.hibernate.stat.spi.StatisticsImplementor;
17+
18+
import org.hibernate.testing.FailureExpected;
1719
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
1820
import org.junit.Test;
1921

@@ -109,6 +111,7 @@ private <TPerson extends Person> List<TPerson> getPersons(Class<TPerson> personC
109111
}
110112

111113
@Test
114+
@FailureExpected( jiraKey = "HHH-14216", message = "The changes introduces by HHH-14216 have been reverted see https://github.com/hibernate/hibernate-orm/pull/5061 discussion")
112115
public void OneToOneCacheByForeignKey() throws Exception {
113116
OneToOneTest(PersonByFK.class, DetailsByFK.class);
114117
}

0 commit comments

Comments
 (0)