diff --git a/changelog.txt b/changelog.txt index ad34cd5c2565..c282289722cc 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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) ------------------------------------------------------------------------------------------------------------------------ diff --git a/hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java b/hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java index 2033da81b140..9ec9c3fd445f 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java @@ -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 @@ -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; } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/onetoone/cache/OneToOneCacheTest.java b/hibernate-core/src/test/java/org/hibernate/test/onetoone/cache/OneToOneCacheTest.java index d14e6c56a442..0c09734230c7 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/onetoone/cache/OneToOneCacheTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/onetoone/cache/OneToOneCacheTest.java @@ -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; @@ -109,6 +111,7 @@ private List getPersons(Class 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); }