[Hibernate-JIRA] Created: (EJB-300) create-drop with c3p0 causes SQLException
by Chris Redekop (JIRA)
create-drop with c3p0 causes SQLException
-----------------------------------------
Key: EJB-300
URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-300
Project: Hibernate Entity Manager
Issue Type: Bug
Components: EntityManager
Affects Versions: 3.2.1
Environment: hibernate-entitymanager 3.2.1.ga, c3p0 0.9.0, and postgreSQL 8.1.8 or hsqldb 1.8.7
Reporter: Chris Redekop
Attachments: c3p0Test.tar.gz
In the attached test application, an EntityManagerFactory is created and then closed.
Closing the EMF causes line 801 of org.hibernate.impl.SessionFactoryImpl to call getConnectionProvider().close(), which eventually results in c3p0's PooledDataSource being closed.
Line 808 of org.hibernate.impl.SessionFactoryImpl the calls schemaExport.drop(), which attempts to acquire a connection from the data source and causes the following SQLException.
java.sql.SQLException: com.mchange.v2.c3p0.PoolBackedDataSource@fced4 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@9505f [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 9505f, idleConnectionTestPeriod -> 100, initialPoolSize -> 10, maxIdleTime -> 100, maxPoolSize -> 100, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 10, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@80cac9 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 80cac9, jdbcUrl -> jdbc:hsqldb:., properties -> {user=******, password=******, autocommit=true, release_mode=auto} ], preferredTestQuery -> null, propertyCycle -> 300, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, usesTraditionalReflectiveProxies -> false ], factoryClassLocation -> null, identityToken -> fced4, numHelperThreads -> 3 ] has been closed() -- you can no longer use it.
This exception is swallowed so it does not cause a test error, but it does appear in the console output.
--
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
16 years, 2 months
[Hibernate-JIRA] Created: (ANN-651) Bad SQL generated when using the @OrderBy annotation
by Eyal Lupu (JIRA)
Bad SQL generated when using the @OrderBy annotation
----------------------------------------------------
Key: ANN-651
URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-651
Project: Hibernate Annotations
Issue Type: Bug
Affects Versions: 3.3.0.ga
Environment: Hibernate Annotations 3.3.0.GA
Hibernate 3.2.5
EntityManager 3.3.1.GA
Hibernate Validator 3.0.0.GA
Oracle 10g
Reporter: Eyal Lupu
Attachments: orderBy-bug-test-case.zip
When upgrading to the versions above a code which works for months now stopped working, the reason is that Hibernate generates a bad SQL statment.
Attached is a test case:
Having the following classes
Parent
/ \
Child1 Child2
The parent has a property named 'elementType'. Child1 has a list of Child2 (its sibling) which is ordered using the
@OrderBy("elementType") annotation. When fetching a Child1 instance, using the EntityManager.find(...) method, Hibernate generates an
invalid SQL:
Hibernate: /* load bug.Child1 */ select child1x0_.ID as ID0_1_, child1x0_.ELEMENT_TYPE as ELEMENT3_0_1_, elements1_.PARENT_ID as PARENT4_3_, elements1_.ID as ID3_, elements1_.ID as ID0_0_, elements1_.ELEMENT_TYPE as ELEMENT3_0_0_, elements1_.PARENT_ID as PARENT4_0_0_ from BUG_TST child1x0_ left outer join BUG_TST elements1_ on child1x0_.ID=elements1_.PARENT_ID where child1x0_.ID=? and child1x0_.DTYPE='Child1' order by BUG_TST.ELEMENT_TYPE asc
The error is in the order by clause, you can't use the table name if you gave it an alias - you should use the alias.
* If I move the 'elementType' property down to Child2 it works!
*If I remove the @OrderBy it also works
-- It is hard to know if this is an Hibernate core or Hibernate annotation bug.
This is the exception:
Caused by: org.hibernate.exception.SQLGrammarException: could not load an entity: [bug.Child1#1]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1874)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3044)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:395)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:195)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:103)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:175)
... 1 more
Caused by: java.sql.SQLException: ORA-00904: "BUG_TST"."ELEMENT_TYPE": 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:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:799)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1038)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:839)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1133)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3329)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
... 13 more
-- Attached is a test case
--
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
16 years, 3 months
[Hibernate-JIRA] Created: (HHH-2281) CLONE -Calling Session.connection() generates java.lang.IllegalArgumentException: interface org.hibernate.jdbc.ConnectionWrapper is not visible from class loader
by Sergey Polzunov (JIRA)
CLONE -Calling Session.connection() generates java.lang.IllegalArgumentException: interface org.hibernate.jdbc.ConnectionWrapper is not visible from class loader
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Key: HHH-2281
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2281
Project: Hibernate3
Type: Bug
Versions: 3.2.1
Environment: Hibernate checked out from trunk; revision 10717
Reporter: Sergey Polzunov
Calling Session.connection() always generates an exception. Here is the stacktrace I get from the attached test case:
Exception in thread "main" java.lang.IllegalArgumentException: interface org.hibernate.jdbc.ConnectionWrapper is not visible from class loader
at java.lang.reflect.Proxy.getProxyClass(Proxy.java:353)
at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:581)
at org.hibernate.jdbc.BorrowedConnectionProxy.generateProxy(BorrowedConnectionProxy.java:56)
at org.hibernate.jdbc.ConnectionManager.borrowConnection(ConnectionManager.java:163)
at org.hibernate.jdbc.JDBCContext.borrowConnection(JDBCContext.java:111)
at org.hibernate.impl.SessionImpl.connection(SessionImpl.java:359)
at TestSession.main(TestSession.java:16)
Changing the Connection.class.getClassLoader() to BorrowedConnectionProxy.class.getClassLoader() on line 57 in the generateProxy() method solves the problem. I am not very familiar with class loaders so I don't know if this is likeley to cause other problems elsewhere. Removing the ConnectionWrapper.class from the PROXY_INTERFACES array in the org.hibernate.jdbc.BorrowedConnectionProxy also solves the problem, but I guess it was added for a reason.
--
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
16 years, 3 months
[Hibernate-JIRA] Created: (HHH-2254) A query validation bug produces QueryException: "Expected positional parameter count: 1, actual parameters: [Parent@bec357b] [from Child this where this.id.parent = ?]"
by Hernan Liendo (JIRA)
A query validation bug produces QueryException: "Expected positional parameter count: 1, actual parameters: [Parent@bec357b] [from Child this where this.id.parent = ?]"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Key: HHH-2254
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2254
Project: Hibernate3
Type: Bug
Components: query-hql
Versions: 3.2.0.ga
Environment: Hibernate 3.2 using Sybase. However this is not an environment caused problem. It's supposed to happen in every environment.
Reporter: Hernan Liendo
-- Short description ============================================================================ --
A query validation bug produces QueryException: "Expected positional parameter count: 1, actual parameters: [Parent@bec357b] [from Child this where this.id.parent = ?].
Both Parent and Child use composite keys.
-- Context ====================================================================================== --
Having composite keys for a Parent class and a Child class, I want to retrieve childs that belong to an specific Parent.
-- Parent Definition ============================================================================ --
public class Parent {
public ParentId ParentId;
...
}
public class ParentId {
private String idField1;
private int idField2;
...
}
// the parent mapping
<hibernate-mapping>
<class mutable="false" table="xx" name="Parent">
<composite-id class="ParentId" access="field" name="parentId">
<key-property column="idField1" access="field" name="idField1"/>
<key-property column="idField2" access="field" name="idField2"/>
</composite-id>
</class>
</hibernate-mapping>
-- Child Definition ============================================================================ --
public class Child {
public ChildId childId;
...
}
public class ChildId {
public Parent parent;
public String aditionalIdField;
...
}
// the mapping
<hibernate-mapping>
<class mutable="false" table="yyy" name="Child">
<composite-id class="ChildId" access="field" name="childId">
<key-many-to-one name="parent" class="Parent" access="field">
<column name="idField1" not-null="true" />
<column name="idField2" not-null="true" />
</key-many-to-one>
<key-property column="aditionalIdField" access="field" name="aditionalIdField"/>
</composite-id>
</class>
</hibernate-mapping>
-- HQL Statement ============================================================================ --
from Child this where this.childId.parent = ?
or
from Child this where this.id.parent = ? // using aliased id
-- The Exception ============================================================================ --
org.hibernate.QueryException: Expected positional parameter count: 1, actual parameters: [Parent@bec357b] [from Child this where this.childId.parent = ?]
at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:319)
at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:275)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:75)
...
-- The Problem ============================================================================ --
class: org.hibernate.impl.AbstractQueryImpl
method: protected void verifyParameters(boolean reserveFirstParameter) throws HibernateException
line: 286
The method validates parameters. It resolves the "positionalValueSpan" variable witch in my case gets the value of 2 (One for parent's idField1 and the other for parent's idField2).
The method compares positionalValueSpan (2) with parameterMetadata.getOrdinalParameterCount() witch it is 1 (the quantity of "?" signs in the HQL statement".
This bug only happens when:
1. composed keys are used (and)
2. having a parent-child relationship (and)
3. resolving children from certain parent.
-- Hibernate user workaround ============================================================================ --
Not to use a parent instance variable in the Child class.
Hope this helps. If you guys need the source code in order to check the bug, please let me know it. Good luck!
Hernan
--
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
16 years, 3 months