[Hibernate-JIRA] Created: (HHH-3589) Sql generated for criteria intermittently causes "invalid identifier" error by assigning incorrect table alias to query elements
by Todd Currie (JIRA)
Sql generated for criteria intermittently causes "invalid identifier" error by assigning incorrect table alias to query elements
--------------------------------------------------------------------------------------------------------------------------------
Key: HHH-3589
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3589
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.1
Environment: Hibernate Core 3.3.1.GA
Oracle 10.02.03
JRE Q1.5.0_16-b02
Reporter: Todd Currie
Application is encountering intermittent ORA-00904 "invalid identifier" errors in production and test build environment. Error occurs approximately 1:460 executions in the test build environment. In each occurence it happens with a different test, but when it occurs every criteria query generated for that test class fails. In production typically causes application to crash because of the unexpected exception thrown.
The issue appears to be caused during construction of the CriteriaJoinWalker. The CriteriaLoader creates a CriteriaQueryTranslator that is responsible for the where condition and order by for non-projection queries (or additionally the select and group by for projection queries). The translator constructor is passed the CriteriaQueryTranslator.ROOT_SQL_ALIAS, "this_", which it uses for its rootSQLAlias. But when the CriteriaLoader next creates the CriteriaJoinWalker instance that is responsible for the rest of the query elements, it does not use the constructor that takes the root alias. The CriteriaJoinWalker then calls super(persister, factory, enabledFilters, alias); with a null passed in the alias parameter. The constructor in the parent class, AbstractEntityJoinWalker, calls generateRootAlias when the alias parameter is null. The method generateRootAlias is implemented both in the parent class JoinWalker and the child class CriteriaJoinWalker. To implement this form of polymorphism, java uses dynamic method binding to determine which method to call for the instance at run time. It appears that most of the time it calls the CriteriaJoinWalker implementation of generateRootAlias function which is hard coded to return CriteriaQueryTranslator.ROOT_SQL_ALIAS, "this_". The queries then generated by the CriteriaJoinWalker then execute correctly. But intermittently it calls the JoinWalker implementation which uses the passed in persistor's entityName to generate the table alias. This table alias that is then used for the rest of the query is different then the alias used by the CriteriaQueryTranslator and the resulting sql generates the invalid identifier error seen upon execution.
This can be fixed in a number of ways.
1) pass the CriteriaQueryTranslator.ROOT_SQL_ALIAS into the constructor for the CriteriaJoinWalker.
2) make the generateRootAlias abstract in the JoinWalker (less reliable).
3) use an AbstractFactory pattern to construct the objects (more work).
I have implemented #1 in our environment and am working on generating a clean test case to submit here. But for those who are interested here is the patch:
### Eclipse Workspace Patch 1.0
#P hibernate-core
Index: src/main/java/org/hibernate/loader/criteria/CriteriaLoader.java
===================================================================
--- src/main/java/org/hibernate/loader/criteria/CriteriaLoader.java (revision 15443)
+++ src/main/java/org/hibernate/loader/criteria/CriteriaLoader.java (working copy)
@@ -94,7 +94,8 @@
factory,
criteria,
rootEntityName,
- enabledFilters
+ enabledFilters,
+ CriteriaQueryTranslator.ROOT_SQL_ALIAS
);
initFromWalker(walker);
Example stack trace:
could not execute query; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:615)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:1051)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:1044)
at com.onstation.service.PersistenceServiceImpl.findByCriteria(Unknown Source)
at com.onstation.service.MailingServiceTest.shouldFailToFindStateConversions(MailingServiceTest.java:52)
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2231)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
at org.hibernate.loader.Loader.list(Loader.java:2120)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1596)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
at org.springframework.orm.hibernate3.HibernateTemplate$36.doInHibernate(HibernateTemplate.java:1061)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
Caused by: java.sql.SQLException: ORA-00904: "THIS_"."SOURCE": invalid identifier
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:810)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1039)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:850)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1134)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3339)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3384)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1808)
at org.hibernate.loader.Loader.doQuery(Loader.java:697)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2228)
Example query:
Hibernate:
select
stateconve0_.FAILEDID as FAILEDID311_0_,
stateconve0_.CREATED as CREATED311_0_,
stateconve0_.LOG as LOG311_0_,
stateconve0_.SOURCE as SOURCE311_0_
from
STATECONVERTFAILED stateconve0_
where
this_.SOURCE=?
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
15 years, 2 months
[Hibernate-JIRA] Created: (HHH-4449) NPE during inserting new audited entity with reference to another proxy entity if proxy.lazyInitializer.session is null
by Eugene Goroschenya (JIRA)
NPE during inserting new audited entity with reference to another proxy entity if proxy.lazyInitializer.session is null
-----------------------------------------------------------------------------------------------------------------------
Key: HHH-4449
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4449
Project: Hibernate Core
Issue Type: Bug
Components: envers
Affects Versions: 3.5.0.Beta-1, 3.3.2
Reporter: Eugene Goroschenya
NPE during inserting new audited entity with reference to another proxy entity if proxy.lazyInitializer.session is null
java.lang.NullPointerException
at org.hibernate.envers.tools.Tools.getTargetFromProxy(Tools.java:74)
at org.hibernate.envers.event.AuditEventListener.generateBidirectionalCollectionChangeWorkUnits(AuditEventListener.java:108)
at org.hibernate.envers.event.AuditEventListener.onPostInsert(AuditEventListener.java:152)
at org.hibernate.action.EntityIdentityInsertAction.postInsert(EntityIdentityInsertAction.java:113)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:89)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at com.jcatalog.core.persistence.hibernate.HibernateSaveOrUpdateListener.onSaveOrUpdate(HibernateSaveOrUpdateListener.java:31)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:527)
at org.hibernate.engine.CascadingAction$5.cascade(CascadingAction.java:241)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:292)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:240)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:193)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:320)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:266)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:243)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:193)
at org.hibernate.engine.Cascade.cascade(Cascade.java:154)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:479)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:357)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at com.jcatalog.core.persistence.hibernate.HibernateSaveOrUpdateListener.onSaveOrUpdate(HibernateSaveOrUpdateListener.java:31)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:527)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:523)
at org.springframework.orm.hibernate3.HibernateTemplate$16.doInHibernate(HibernateTemplate.java:747)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:744)
at com.jcatalog.jsfeditor.facade.HibernateEditorFacade.save(HibernateEditorFacade.java:33)
It seems It happens when hibernate session was cleared so proxy.lazyInitializer.session is set to null but this object can be used later as refernce in other entity.
Just for information such use case works OK with hibernate without Envers as far as we not try call getters of proxy with null session.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
15 years, 2 months
[Hibernate-JIRA] Created: (HHH-4437) ToOneDelegateSessionImplementor breaks Hibernate.getClass(auditedEntity.proxyOfnotAuditedEntity)
by Eugene Goroschenya (JIRA)
ToOneDelegateSessionImplementor breaks Hibernate.getClass(auditedEntity.proxyOfnotAuditedEntity)
------------------------------------------------------------------------------------------------
Key: HHH-4437
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4437
Project: Hibernate Core
Issue Type: Bug
Components: envers
Affects Versions: 3.3.x
Reporter: Eugene Goroschenya
Priority: Blocker
Probably there is mistake in changes applied for HHH-4010 that leads to incorrect working of Hibernate.getClass(proxy) method.
See ToOneDelegateSessionImplementor#doImmediateLoad(String entityName)
...
Session session = versionsReader.getSession();
return session.get(entityClass, (Serializable) entityId);
...
It can return proxy but Hibernate SessionImplementor interface says
/**
* Load an instance immediately. This method is only called when lazily initializing a proxy.
* Do not return the proxy.
*/
public Object immediateLoad(String entityName, Serializable id) throws HibernateException;
Probably solution is to use delegate.doImmediateLoad(entityClass, (Serializable) entityId) instead of session.get(entityClass, (Serializable) entityId)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
15 years, 2 months
[Hibernate-JIRA] Created: (HV-265) Constraints not loaded consistently for inherited classes
by Jaro Kuruc (JIRA)
Constraints not loaded consistently for inherited classes
---------------------------------------------------------
Key: HV-265
URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-265
Project: Hibernate Validator
Issue Type: Bug
Components: mapping
Affects Versions: 4.0.1
Environment: Win XP, Sun Java 1.6
Reporter: Jaro Kuruc
Attachments: hibernate-validator-tests.zip
Hi, please find attached project demonstrating inconsistency in loading constraints when using annotations vs. XML mappings. This is sometimes causing that validator does not validate field 'detail.competition.name' in org.hibernate.validator.xml.Competition class.
The test demonstrates 3 cases:
1. Using default configuration on top of annotated beans - works as expected
2. Using explicit configuration mappings on top of annotated beans - works as expected
3. Using explicit configuration mappings on top of non-annotated beans - does not work as expected
The third case works only if both subclasses of org.hibernate.validator.xml.Competition (org.hibernate.validator.xml.PersonCompetition and org.hibernate.validator.xml.TeamCompetition) are defined in mappings file as beans, even though they are not adding any new fields to validate. The problem is that in this case, the field they inherited is ignored by validator and not validated.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
15 years, 2 months
[Hibernate-JIRA] Created: (HHH-4114) ASTParserLoadingTest fails due to missing "bit_length" function
by strong liu (JIRA)
ASTParserLoadingTest fails due to missing "bit_length" function
---------------------------------------------------------------
Key: HHH-4114
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4114
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.5.0.Beta-1, 3.3.2, 3.5
Environment: PostgreSQL 8.3.7
Reporter: strong liu
Assignee: strong liu
Priority: Minor
Fix For: 3.3.x, 3.5, 3.3.2
Test testEJBQLFunctions fails when executing the following query on PostgreSQL:
from Animal a where bit_length(a.bodyWeight) = 24
Similar to JBPAPP-1036, but our target at that time was PostgreSQL 8.2.3 (on which, the test passes with no problems).
Log excerpt:
12:49:28,109 WARN JDBCExceptionReporter:100 - SQL Error: 0, SQLState: 42883
12:49:28,110 ERROR JDBCExceptionReporter:101 - ERROR: function bit_length(real) does not exist
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
15 years, 2 months