-->
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.  [ 10 posts ] 
Author Message
 Post subject: Problems with bulk updates
PostPosted: Tue Sep 06, 2005 3:13 am 
Newbie

Joined: Tue Sep 06, 2005 2:58 am
Posts: 7
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0

Mapping documents:
<class name="Incident" table="OPR_INCIDENTS">
<meta attribute="extends" inherit="false">BaseBusinessObject</meta>
<id name="id" type="java.lang.Long">
<column name="SEQUENCE_ID" length="18" not-null="true" unique="true" sql-type="NUMBER" />
<generator class="hibernate.OpRiskKeyGenerator">
<param name="sequence">OPR_PRIMARYKEYGEN</param>
<param name="max_lo">100</param>
</generator>
</id>

<timestamp column="MODIFIED_TMSP" name="modifiedTmsp" />

<property name="incidentId" type="java.lang.String">
<column name="INCIDENT_ID" length="30" not-null="true" unique="true" sql-type="VARCHAR2" />
</property>
<property name="name" type="java.lang.String">
<column name="NAME" length="40" not-null="true" sql-type="VARCHAR2" />
</property>
<property name="descr" type="java.lang.String">
<column name="DESCR" length="3000" not-null="true" sql-type="VARCHAR2" />
</property>
<component name="costPayingOu" class="model.type.Ou" >
<property name="department" type="java.lang.String">
<column name="COST_PAYING_OU_DEPARTMENT" length="20" not-null="false" sql-type="VARCHAR2" />
</property>
<property name="uwi" type="java.lang.String">
<column name="COST_PAYING_OU_UWI" length="40" not-null="false" sql-type="VARCHAR2" />
</property>
</component>
</class>

Full stack trace of any exception that occurs:
org.hibernate.hql.ast.QuerySyntaxError: expecting EQ, found '.' near line 1, column 33 [update Incident set costPayingOu.department=:newValue where costPayingOu.uwi=:uwiName]
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:63)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:215)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:127)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:865)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:89)
at batch.OEStructureImport.searchOpRiskUpdateOE(OEStructureImport.java:213)
at batch.OEStructureImport.execute(OEStructureImport.java:159)
at batch.OpriskBatchBase.run(OpriskBatchBase.java:47)
at batch.OEStructureImport.main(OEStructureImport.java:111)
Caused by: line 1:33: expecting EQ, found '.'
at antlr.Parser.match(Parser.java:211)
at org.hibernate.hql.antlr.HqlBaseParser.assignment(HqlBaseParser.java:400)
at org.hibernate.hql.antlr.HqlBaseParser.setClause(HqlBaseParser.java:338)
at org.hibernate.hql.antlr.HqlBaseParser.updateStatement(HqlBaseParser.java:183)
at org.hibernate.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:133)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:209)
... 10 more

The generated SQL (show_sql=true):
2005-09-06 08:41:20,655 INFO NOPID update Incident set costPayingOu.department=:newValue where costPayingOu.uwi=:uwiName ; OEStructureImport
08:41:20,935 ERROR PARSER - *** ERROR: line 1:33: expecting EQ, found '.'

Explanation:
I'm trying to perform a bulk update but am always receiving a parser exception. It is no DB exception, it doesn't even get that far. Is it not possible to update attributes within a composite?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 3:17 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
Post the HQL behind this SQL.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 3:25 am 
Newbie

Joined: Tue Sep 06, 2005 2:58 am
Posts: 7
Sorry, here's the HQL code:

String update = "update Incident set costPayingOu.department=:newValue where costPayingOu.uwi=:uwiName";
Query q = HibernateSessionManager.findHibernateSession().createQuery(update);
q.setString("newValue", "abc");
q.setString("uwiName", uwi);

int count = q.executeUpdate();


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 3:38 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
the_dude wrote:
Sorry, here's the HQL code:

String update = "update Incident set costPayingOu.department=:newValue where costPayingOu.uwi=:uwiName";


What does this do?

String update = "update Incident costPayingOu set costPayingOu.department=:newValue where costPayingOu.uwi=:uwiName";


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 3:53 am 
Newbie

Joined: Tue Sep 06, 2005 2:58 am
Posts: 7
That's the problem, it doesn't do anything. If you see the stacktrace there is a problem with the HQL statement.
What I want to do is update all Incidents. Set the department attribute to a new value where the uwi is equals "abc".
The standard sql would be:

update OPR_INCIDENTS set COST_PAYING_OU_DEPARTMENT="abc" where COST_PAYING_OU_UWI=?

There seems to be a problem referencing the composite property costPayingOu.department

The Error is (provided in the Stacktrace): expecting EQ, found '.' near line 1, column 33. That is exactly the position where I reference the department property of the component costPayingOu.

Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 4:05 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
the_dude wrote:
That's the problem, it doesn't do anything.


Just a quick check, you did notice the slight change to your code, right?

Well, if all else fails, pass that SQL to Session.createSQLQuery()


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 4:29 am 
Newbie

Joined: Tue Sep 06, 2005 2:58 am
Posts: 7
Yeah, I'm aware of the change, thankx.

Sorry, can't use SQL, only selects are supported, that's why I have to use HQL.

Any ideas why the statement fails?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 4:40 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
No ideas, but thanks for the heads up on SELECTs only.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 11:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Try two things:

(1) use an alias in the query
(2) use Hibernate 3.1 beta 2


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 4:44 am 
Newbie

Joined: Tue Sep 06, 2005 2:58 am
Posts: 7
Thankx for the reply.

Unfortunetly option 1 doesn't work and I'm not able to use 3.1, standards!
I'm ging to have to iterate over all objects one by one.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.