-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: buk update with no join
PostPosted: Mon Jun 20, 2005 11:23 am 
Newbie

Joined: Thu Feb 10, 2005 12:29 pm
Posts: 6
Hello!
i'm trying to make a bulk update:

String hqlUpdate = "update GroupMobilePhoneAddressesElement "
+" set groupCount = :newGroupCount "
+" where mobilePhoneAddress.id = :theMpaId";
session.createQuery( hqlUpdate )
.setString( "newGroupCount", ""+newGroupCount )
.setString( "theMpaId", ""+theMpaId)
.executeUpdate();


the erroneous sql generated is:
Hibernate: update rel_group_mobile_phone_address set GROUP_COUNT=? where groupmobil0_.ID=?

and the oracle error is java.sql.SQLException: ORA-00904: not valid column name

how I can address the id of mobilePhoneAddress correctly? It doesn't require a join because the mobilePhoneAddress.id is stored in the table rel_group_mobile_phone_address (look down the mapping...)

thank you for help




Hibernate version:3.0.5

Mapping documents:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="it.mobis.sms.GroupMobilePhoneAddressesElement" table="rel_group_mobile_phone_address">
<cache usage="read-write"/>
<id name="id" type="long" unsaved-value="0" >
<column name="ID" sql-type="number(10,0)" not-null="true"/>
<generator class="sequence">
<param name="sequence">GROUP_MOBILE_PHONE_ADDR_SEQ</param>
</generator>
</id>
<!--<timestamp column="TIMESTAMP" name="timestamp" />-->
<property name="insertDate">
<column name="INSERT_DATE" not-null="true"/>
</property>
<property name="removeDate">
<column name="REMOVE_DATE"/>
</property>
<property name="groupCount">
<column name="GROUP_COUNT" sql-type="number(7,0)" not-null="true"/>
</property>
<!--
<property name="pos">
<column name="POS" sql-type="number(10,0)" not-null="true"/>
</property>
-->
<many-to-one name="mobilePhoneAddress" class="it.mobis.sms.MobilePhoneAddress">
<column name="MOBILE_PHONE_ADDRESS_ID" sql-type="number(10,0)" not-null="true"/>
</many-to-one>

<many-to-one name="group" class="it.mobis.sms.Group">
<column name="GROUP_ID" sql-type="number(7,0)" not-null="true"/>
</many-to-one>
</class>
</hibernate-mapping>

stack trace of exception :

org.hibernate.exception.SQLGrammarException: could not execute update query
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.hql.ast.UpdateStatementExecutor.execute(UpdateStatementExecutor.java:99)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:297)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:871)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:89)
at it.mobis.sms.service.GroupServiceBean.updateAllGroupMpa_GroupCount(GroupServiceBean.java:185)
at it.mobis.sms.service.GroupServiceBean.removeMpaImpl(GroupServiceBean.java:237)
at it.mobis.sms.service.AbstractGroupServiceBean.removeMpa(AbstractGroupServiceBean.java:147)
at it.mobis.sms.service.JOnASGroupServiceEJBRemote.removeMpa(JOnASGroupServiceEJBRemote.java:177)
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:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at org.objectweb.carol.rmi.jrmp.server.JUnicastServerRef.runDispatch(JUnicastServerRef.java:165)
at org.objectweb.carol.rmi.jrmp.server.JUnicastServerRef.dispatch(JUnicastServerRef.java:149)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.sql.SQLException: ORA-00904: nome di colonna non valido

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:169)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1405)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:822)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:1602)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1527)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2045)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:395)
at org.hibernate.hql.ast.UpdateStatementExecutor.execute(UpdateStatementExecutor.java:76)
... 20 more
)
at it.mobis.sms.service.GroupServiceBean.removeMpaImpl(GroupServiceBean.java:244)
at it.mobis.sms.service.AbstractGroupServiceBean.removeMpa(AbstractGroupServiceBean.java:147)
at it.mobis.sms.service.JOnASGroupServiceEJBRemote.removeMpa(JOnASGroupServiceEJBRemote.java:177)
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:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at org.objectweb.carol.rmi.jrmp.server.JUnicastServerRef.runDispatch(JUnicastServerRef.java:165)
at org.objectweb.carol.rmi.jrmp.server.JUnicastServerRef.dispatch(JUnicastServerRef.java:149)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:534)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
at org.objectweb.carol.rmi.jrmp.server.JRemoteCall.executeCall(JRemoteCall.java:91)
at org.objectweb.carol.rmi.jrmp.server.JUnicastRef.invoke(JUnicastRef.java:165)
at it.mobis.sms.service.JOnASGroupServiceEJBRemote_Stub.removeMpa(Unknown Source)
at it.mobis.sms.proxy.AbstractGroupProxy.removeMpa(AbstractGroupProxy.java:237)
at it.mobis.sms.smslucca.servlets.ModifyDataServlet.doGetImpl(ModifyDataServlet.java:75)
at it.mobis.util.web.ServletBase.doGet(ServletBase.java:66)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:98)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:172)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)


Name and version of the database you are using:
oracle 8.1.7


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 20, 2005 11:35 am 
Newbie

Joined: Thu Feb 10, 2005 12:29 pm
Posts: 6
addressing the real column name of the database it work correctly.

String hqlUpdate = "update GroupMobilePhoneAddressesElement "
+" set groupCount = :newGroupCount "
+" where MOBILE_PHONE_ADDRESS_ID = :theMpaId";

int updatedEntities = session.createQuery( hqlUpdate )
.setString( "newGroupCount", ""+newGroupCount )
.setString( "theMpaId", ""+theMpaId)
.executeUpdate();


generated sql:
Hibernate: update rel_group_mobile_phone_address set GROUP_COUNT=? where MOBILE_PHONE_ADDRESS_ID=?


it is the correct way to use the bulk update or in a newer version of hibenate it will not work?[/i][/b]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 20, 2005 12:28 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
Try something like this:

String hqlUpdate = "update GroupMobilePhoneAddressesElement "
+" set groupCount = :newGroupCount "
+" where mobilePhoneAddress = :theMpaObject";
session.createQuery( hqlUpdate )
.setString( "newGroupCount", ""+newGroupCount )
.setEntity( "theMpaObject", ""+theMpaObject)
.executeUpdate();

I think that your first attempt was failing because saying mobilePhoneAddress.id is an HQL way of joining, which is not allowed in HQL updates.

By using setEntity, Hibernate will know to check for 'id' equality, which is what you were doing explicity in your second post.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 21, 2005 3:08 am 
Newbie

Joined: Thu Feb 10, 2005 12:29 pm
Posts: 6
thank you very much. It works.

This is the code:

String hqlUpdate = "update GroupMobilePhoneAddressesElement "
+" set groupCount = :newGroupCount "
+" where mobilePhoneAddress = :theMpa";
int updatedEntities = session.createQuery( hqlUpdate )
.setLong( "newGroupCount", newGroupCount )
.setEntity( "theMpa", mpa)
.executeUpdate();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.