[Hibernate-JIRA] Commented: (HBX-469) Named Query DAO methods with Primitive types fail to compile
by Joe Porcheddu (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HBX-469?page=co... ]
Joe Porcheddu commented on HBX-469:
-----------------------------------
This issue still occurs with Hibernate Tools 3.2.0.ga.
Maven dependency used:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools</artifactId>
<version>3.2.0.ga</version>
</dependency>
> Named Query DAO methods with Primitive types fail to compile
> ------------------------------------------------------------
>
> Key: HBX-469
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-469
> Project: Hibernate Tools
> Issue Type: Bug
> Components: hbm2java
> Affects Versions: 3.1beta1
> Reporter: James Schopp
> Fix For: 3.2beta6
>
>
> if you define a name query that receives a primitive or wrapper parameter, then the DAO method for the name query will always be generated with "primitive" type. This failsto compile, since the call to query.setParameter("paramName", value); takes an object, not a primitive. For example:
> <query name="com.mycom.persistence.Account.findCommercialAccountById">
> from Account where accountTypeClass='C' and accountNumber=:accountNumber
> <query-param name="accountNumber" type="java.lang.Long" />
> </query>
> This generates the code
> public List findCommercialAccountById(long accountNumber) {
> Query query = getSession(false)
> .getNamedQuery("com.alldata.ecis.persistence.Account.findCommercialAccountById");
> query.setParameter("accountNumber", accountNumber);
> return query.list();
> }
> This code does not compile.
> I beleive the fix might be as simple as modifying Cfg2JavaTool.asFinderArgumentList():
> if ( type instanceof PrimitiveType ) {
> typeClass = ( (PrimitiveType) type ).getPrimitiveClass();
> }
> else {
> typeClass = type.getReturnedClass();
> }
> I think this should always return the type.getReturnedClass(), and never the primitive...
> ALSO: it would ne nice to have another Cfg2JavaTool function like
> asFinderArgumentList
> but that generates the list as parameters to the call, not the function definition.
> For example, if a named query takes params:
> Long accountNumer, String accountName
> then, maybe have function called
> asFinderCallerArgumentList()
> which would return
> accountNumer, accountName
--
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, 11 months
[Hibernate-JIRA] Created: (HHH-3150) "ORA-00918: column ambiguously defined" on MERGE/UPDATE when using Joined Subclasses strategy.
by Peter Lupo (JIRA)
"ORA-00918: column ambiguously defined" on MERGE/UPDATE when using Joined Subclasses strategy.
----------------------------------------------------------------------------------------------
Key: HHH-3150
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3150
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.6
Environment: Core 3.2.5, Annotations 3.3.0.GA, EntityManager 3.3.1.GA, Oracle10g Express and MS SQL Server 2005.
Reporter: Peter Lupo
Attachments: FromElementType.java
When using Joined Subclass strategy, an entityManager.merge(detatchedSubclassInstance) on a subclass instance result in a query like this:
insert into HT_TB_AMBIENTECONFIGURADO select ambienteco0_.ID as ID from TB_AMBIENTECONFIGURADO ambienteco0_ inner join TB_AMBIENTE ambienteco0_1_ on ambienteco0_.ID=ambienteco0_1_.ID where ID=33367
The "WHERE" condition is not using the table alias. The join is made on the same column, so it shouldn't matter from which table it would be get. Even then, Oracle complains with "ORA-00918: column ambiguously defined" as in the stacktrace included at the end of this description.
The fix is presented by someone with the same problem on a MS SQL Server 2005 database here: http://forums.hibernate.org/viewtopic.php?t=969471
I have applied his fix and tested. It works correctly, generating a query with the table alias. The fixed class is attached with commentaries marking what has been changed (lines 374 to 383).
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not insert/select ids for bulk update
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
at org.hibernate.ejb.QueryImpl.executeUpdate(QueryImpl.java:59)
at br.ufrj.cos.lens.taba.controle.gerencia.ambiente.CriaEntity.criaAmbConf(CriaEntity.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.hibernate.exception.SQLGrammarException: could not insert/select ids for bulk update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.hql.ast.exec.MultiTableUpdateExecutor.execute(MultiTableUpdateExecutor.java:127)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:396)
at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1141)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
at org.hibernate.ejb.QueryImpl.executeUpdate(QueryImpl.java:50)
... 21 more
Caused by: java.sql.SQLException: ORA-00918: column ambiguously defined
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
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.executeForRows(T4CPreparedStatement.java:1120)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1279)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3415)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3498)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:251)
at org.hibernate.hql.ast.exec.MultiTableUpdateExecutor.execute(MultiTableUpdateExecutor.java:118)
... 26 more
--
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, 11 months
[Hibernate-JIRA] Created: (EJB-355) query generates invalid sql: Column 'id' in where clause is ambiguous
by sagi mann (JIRA)
query generates invalid sql: Column 'id' in where clause is ambiguous
---------------------------------------------------------------------
Key: EJB-355
URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-355
Project: Hibernate Entity Manager
Issue Type: Bug
Components: EntityManager
Affects Versions: 3.3.2.GA
Environment: MySQL 5.0.1
Reporter: sagi mann
Entities:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
//@DiscriminatorColumn(name="classname", discriminatorType=DiscriminatorType.STRING, length=255)
public abstract class JoinedBaseClass implements Serializable {
@Id
@GeneratedValue
public Long getId() { return this.id; }
public void setId(Long id) { this.id = id; }
private Long id;
}
@Entity
//@DiscriminatorValue(value="joinedsubclass1")
public class JoinedSubClass1 extends JoinedBaseClass {
@Basic
public String getSubProp1() { return bp1; }
public void setSubProp1(String bp) { this.bp1 = bp; }
private String bp1;
}
Code in EJB
em.createQuery("delete from JoinedSubClass1 c where c.id = 3")
.executeUpdate();
The generated SQL (from MySQL trace file):
create temporary table if not exists HT_JoinedSubClass1 (id bigint not null)
insert into HT_JoinedSubClass1 select joinedsubc0_.id as id from JoinedSubClass1 joinedsubc0_ inner join JoinedBaseClass joinedsubc0_1_ on joinedsubc0_.id=joinedsubc0_1_.id where id=3
Note the final 'where' clause. Shouldn't it be where joinedsubc0_.id=3 instead of where id=3 ? When I manually tried to replace the where clause (just to see if the query gives correct output), it works... but Hibernate insists on generating an invalid query. I'm not sure what I need to do in order to instruct Hibernate to generate the correct syntax - this could be a bug.
Full stack trace of any exception that occurs:
SQL Error: 1052, SQLState: 23000
Column 'id' in where clause is ambiguous
EJB5018: An exception was thrown during an ejb invocation on [TestBean]
javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:3869)
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:3769)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:3571)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1354)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1316)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:210)
at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:117)
at $Proxy87.removeSubClass1Bulk(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:154)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:687)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:227)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1846)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1706)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:1088)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:223)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:806)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:563)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2567)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:555)
Caused by: javax.persistence.EntityExistsException: org.hibernate.exception.ConstraintViolationException: could not insert/select ids for bulk delete
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:612)
at org.hibernate.ejb.QueryImpl.executeUpdate(QueryImpl.java:58)
at pu1.TestBean.removeSubClass1Bulk(TestBean.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1067)
at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:176)
at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2895)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:3986)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:203)
... 17 more
Caused by: org.hibernate.exception.ConstraintViolationException: could not insert/select ids for bulk delete
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.hql.ast.exec.MultiTableDeleteExecutor.execute(MultiTableDeleteExecutor.java:102)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:396)
at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1141)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
at org.hibernate.ejb.QueryImpl.executeUpdate(QueryImpl.java:49)
... 27 more
Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'id' in where clause is ambiguous
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1011)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2019)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1937)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1922)
at org.hibernate.hql.ast.exec.MultiTableDeleteExecutor.execute(MultiTableDeleteExecutor.java:93)
... 32 more
--
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, 11 months
[Hibernate-JIRA] Created: (HHH-3335) HQL DELETE with sub-select creates invalid SQL
by John Baker (JIRA)
HQL DELETE with sub-select creates invalid SQL
----------------------------------------------
Key: HHH-3335
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3335
Project: Hibernate3
Issue Type: Bug
Components: query-hql
Affects Versions: 3.2.6
Environment: Oracle 10, Java 1.5
Reporter: John Baker
Hello,
Consider two objects, ISSO and Event, where ISSO extends Event and the id is called eventId (maps to variable id). Event also has an attribute time. Now consider this HQL:
delete from ISSO e where e.id in (select ev.id from Event ev where ev.time < 123)
I appreciate this could be written without the subselect but I've simplified a more complex subselect in order to demonstrate the problem. This generates SQL that results in the following Oracle error:
ORA-00918: column ambiguously defined
The SQL generated is as follows:
insert into HT_ISSO select isso0_.eventId as eventId from ISSO isso0_ inner join Event isso0_1_ on isso0_.eventId=isso0_1_.eventId
where eventId in (select event1_.eventId from Event event1_ where event1_.time<23)
And the problem is the eventId following where. This should be using the alias, i.e. the SQL should be:
insert into HT_ISSO select isso0_.eventId as eventId from ISSO isso0_ inner join Event isso0_1_ on isso0_.eventId=isso0_1_.eventId
where isso0_.eventId in (select event1_.eventId from Event event1_ where event1_.time<23)
That's it! Can this be fixed?
Thanks.
--
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, 11 months