[Hibernate-JIRA] Created: (HHH-7133) NaturalIdLoadAccess not correctly working on mutable NaturalId's
by Guenther Demetz (JIRA)
NaturalIdLoadAccess not correctly working on mutable NaturalId's
----------------------------------------------------------------
Key: HHH-7133
URL: https://hibernate.onjira.com/browse/HHH-7133
Project: Hibernate ORM
Issue Type: Bug
Components: core
Affects Versions: 4.1.0
Environment: Hibernate4.1.0, db independent (HSQLDB used in attached testcase)
Reporter: Guenther Demetz
Attachments: TestCaseModifieableNaturalId.jar
1. After updating the value of a mutable NaturalId, the entity object can be retrieved with the new value, but also with the old value.
assertNotSame(session.bySimpleNaturalId(C.class).load("1"), session.bySimpleNaturalId(C.class).load("3")); --> failing
Cause: On deletions the internal NaturalId cache get synchronized properly, but not on modifications (no synchronization provided at all)
2. When inserting or deleting an entity object, the entity-persister of the object's concrete class is considered as cache-region.
When loading an entity object by NaturalId, indeed the entity-persister of the declaring class is considered as cache-region.
Session.byNaturalId(declaringclass).load(...)
As declaringclass may be the superclass of a concrete subclass,
the NaturalId-synchronisation (currently called only on deletions) does synchronize the wrong cache-region.
(it tries to remove the entry in the cache-region of the subclass-persister,
but the entry is actually cached in the cache-region of the superclass persister)
N.B: This issue has nothing to do with spreading @NaturalId across an entity hierarchy (HHH-7129),
in attached testcase the NaturalId is declared exclusively in the root class.
Attached testcase demonstrates both bugs.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
14 years
[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
by Guillaume Smet (JIRA)
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
14 years
[Hibernate-JIRA] Created: (HHH-7158) Regression: null values on NaturalId's at persist-time are causing subsequent NPE's and wrong behaviour
by Guenther Demetz (JIRA)
Regression: null values on NaturalId's at persist-time are causing subsequent NPE's and wrong behaviour
-------------------------------------------------------------------------------------------------------
Key: HHH-7158
URL: https://hibernate.onjira.com/browse/HHH-7158
Project: Hibernate ORM
Issue Type: Bug
Components: core
Affects Versions: 4.1.1
Environment: Hibernate 4.1.1, db-indipendent (hsqldb used in testcase)
Reporter: Guenther Demetz
Attachments: TestCasePersistNullNaturalId.jar
Since Hibernate 4.1.1 it is no more possible to have uninitialized NaturalId values when persisting,
in older versions this was always possible (it was even possible to search NaturalId by null-values).
The problem stays in the new method NaturalIdXrefDelegate$NaturalIdResolutionCache#areSame(...)
where org.hibernate.type.Type#compare(...) is used instead of org.hibernate.type.Type#isEqual(...)
Proposed solution (method NaturalIdResolutionCache#areSame):
if ( !naturalIdTypes[i].isEqual(naturalIdValues[i], values[i], factory)) {
return false;
}
instead of:
if ( naturalIdTypes[i].compare( naturalIdValues[i], values[i] ) != 0 ) {
return false;
}
This makes the first test-case green (see attached Testcase).
The second test-case becomes green, due making method EntityType#isEqual(Object x, Object y, SessionFactoryImplementor factory)
stable against null x,y values. That sould be trivial.
N.B.: Please consider also that the EntityType#compare(Object x, Object y) implementation currently always returns 0 (there's a TODO-note),
whilst EntityType#isEqual(Object x, Object y, SessionFactoryImplementor factory) seems to be a good implementation.
Last but not least: isEqual methods should also be a little bit faster than compare-method, cause the latter must calculate differences.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
14 years
[Hibernate-JIRA] Created: (HHH-6648) @GeneratedValue not setting up auto increment in mysql and h2 dialects
by Brad Maxwell (JIRA)
@GeneratedValue not setting up auto increment in mysql and h2 dialects
----------------------------------------------------------------------
Key: HHH-6648
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6648
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 4.0.0.Beta5
Environment: AS 7.0.1
Reporter: Brad Maxwell
Attachments: h2.txt, mysql.txt
I took this application that uses hibernate and moved it to AS 7.0.1. I found that when using the H2 database, it fails complaining that the id is null. I tried changing it to use the HSQL dialect and had the same issue. Then I changed the datasource and dialect to MySQL and I got the same error. I'm attaching the full stack traces for mysql and h2.
I then switched to Oracle ds / dialect and it worked fine.
I examined the database tables and found that it was not set to auto increment. So I manually modified the database tables and that allowed the hibernate calls to succeed.
@Entity()
@Table()
public class EAPVersion implements Serializable
{
@Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name="id")
private int id;
@Column(name="name")
private String name;
@OneToMany(cascade=CascadeType.ALL) //, mappedBy="id")
@JoinColumn(name="EAPVersion_ID")
private List<Component> components = new ArrayList<Component>();
...
}
...
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Field 'id' doesn't have a default value
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1344)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1277)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1283)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:851)
at com.jboss.support.Cache.getEAPVersions(Cache.java:131)
at com.jboss.support.SourceCodeBean.getEapVersionsItems(SourceCodeBean.java:122)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:302)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)
at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
at org.apache.el.parser.AstValue.getValue(AstValue.java:134)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:187)
at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
... 36 more
Caused by: org.hibernate.exception.GenericJDBCException: Field 'id' doesn't have a default value
at org.hibernate.exception.internal.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:148)
at org.hibernate.exception.internal.SQLStateConverter.convert(SQLStateConverter.java:136)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:131)
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:80)
at $Proxy22.executeUpdate(Unknown Source)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:95)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:54)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2753)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3259)
at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:78)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:273)
at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:301)
at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:192)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:127)
at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:78)
at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:178)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:134)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:64)
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:718)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:694)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:698)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:845)
... 48 more
Caused by: java.sql.SQLException: Field 'id' doesn't have a default value
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2625)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2119)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2415)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2333)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2318)
at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:493)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:124)
... 67 more
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
14 years