[hibernate-issues] [Hibernate-JIRA] Created: (HHH-7167) The new natural id code introduced in 4.1.1 depends on the order the entity persisters are loaded which leads to fatal errors

Guillaume Smet (JIRA) noreply at atlassian.com
Mon Mar 12 16:25:48 EDT 2012


The new natural id code introduced in 4.1.1 depends on the order the entity persisters are loaded which leads to fatal errors
-----------------------------------------------------------------------------------------------------------------------------

                 Key: HHH-7167
                 URL: https://hibernate.onjira.com/browse/HHH-7167
             Project: Hibernate ORM
          Issue Type: Bug
          Components: core
    Affects Versions: 4.1.1
            Reporter: Guillaume Smet
            Priority: Critical


Hi,

After upgrade to 4.1.1, our application doesn't work anymore because the sqlEntityIdByNaturalIdString field of the entity persister is null while it shouldn't be.

The problem is that the new code requires the entityPersisters to be postInstantiate()d in a specific order namely the root entity persister should be initialized before the child classes (which is not guaranteed at all and is not the case in our application because of the way our classes are organized).

In our case, the entities are loaded in this order (pseudo code):
{code}
@Entity
ConcreteClass extends AbstractClass {
}

@Entity
AbstractClass {
@Id, @NaturalId
}
{code}

Which is a problem because of the way AbstractEntityPersister.generateEntityIdByNaturalIdSql() now works:
{code}
private String generateEntityIdByNaturalIdSql() {
		EntityPersister rootPersister = getFactory().getEntityPersister( getRootEntityName() );
		if ( rootPersister != this ) {
			if ( rootPersister instanceof AbstractEntityPersister ) {
				return ( (AbstractEntityPersister) rootPersister ).sqlEntityIdByNaturalIdString;
			}
		}
{code}

-> if the root persister is not postInstantiate()d yet (which is our case here), sqlEntityIdByNaturalIdString is null and so is the one of the concrete class leading to fatal error when trying to execute queries using the natural id.

In this case, we should force the postInstantiation of the root entity persister before using sqlEntityIdByNaturalIdString (or we should at least generate its sqlEntityIdByNaturalIdString).

Feel free to ping me if you need any further information.

-- 
Guillaume

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list