Skip to content

Commit

Permalink
HHH-15045 + HHH-15235 onFlushDirty() invoked on parent entity in a @O…
Browse files Browse the repository at this point in the history
…netoOne relationship when no table columns are changed - PropertyAccessException on merging Bidirectional OneToOne with EmbeddedId - Reverted HHH-14216
  • Loading branch information
dreab8 authored and Sanne committed Sep 27, 2022
1 parent 974201a commit 4eea316
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 33 deletions.
2 changes: 1 addition & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ https://hibernate.atlassian.net/projects/HHH/versions/31844
* [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
* [HHH-14251] - Invalid SQL for @Embedded UPDATE
* [HHH-14249] - MultiLineImport fails when script contains blank spaces or tabs at the end of the last sql statement

* [HHH-14216] - Second-level cache doesn't support @OneToOne

Changes in 5.4.14.Final (April 6, 2020)
------------------------------------------------------------------------------------------------------------------------
Expand Down
46 changes: 14 additions & 32 deletions hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,12 @@ public boolean isOneToOne() {

@Override
public boolean isDirty(Object old, Object current, SharedSessionContractImplementor session) {
if ( isSame( old, current ) ) {
return false;
}

Object oldid = getIdentifier( old, session );
Object newid = getIdentifier( current, session );

return getIdentifierType( session ).isDirty( oldid, newid, session );
return false;
}

@Override
public boolean isDirty(Object old, Object current, boolean[] checkable, SharedSessionContractImplementor session) {
return isDirty(old, current, session);
return false;
}

@Override
Expand Down Expand Up @@ -203,36 +196,25 @@ public boolean useLHSPrimaryKey() {

@Override
public Serializable disassemble(Object value, SharedSessionContractImplementor session, Object owner) throws HibernateException {
if (value == null) {
return null;
}

Object id = ForeignKeys.getEntityIdentifierIfNotUnsaved( getAssociatedEntityName(), value, session );

if ( id == null ) {
throw new AssertionFailure(
"cannot cache a reference to an object with a null id: " +
getAssociatedEntityName()
);
}

return getIdentifierType( session ).disassemble( id, session, owner );
return null;
}

@Override
public Object assemble(Serializable oid, SharedSessionContractImplementor session, Object owner) throws HibernateException {
//the owner of the association is not the owner of the id
Serializable id = ( Serializable ) getIdentifierType( session ).assemble( oid, session, null );

if ( id == null ) {
return null;
}

return resolveIdentifier( id, session );
//this should be a call to resolve(), not resolveIdentifier(),
//because it might be a property-ref, and we did not cache the
//referenced value
return resolve( session.getContextEntityIdentifier(owner), session, owner );
}

/**
* We don't need to dirty check one-to-one because of how
* assemble/disassemble is implemented and because a one-to-one
* association is never dirty
*/
@Override
public boolean isAlwaysDirtyChecked() {
return true;
//TODO: this is kinda inconsistent with CollectionType
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.stat.spi.StatisticsImplementor;

import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;

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

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

0 comments on commit 4eea316

Please sign in to comment.