-->
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.  [ 7 posts ] 
Author Message
 Post subject: How to embed an Update SQL into hibernate mapping file?
PostPosted: Wed Aug 31, 2005 4:00 pm 
Beginner
Beginner

Joined: Tue Jun 21, 2005 1:45 pm
Posts: 38
How do I embed an update sql stmt into hibernate mapping file? I tried using <query/> and <sql-query/> elements but both threw an exception as -

Code:
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
   at java.util.ArrayList.RangeCheck(ArrayList.java:547)
   at java.util.ArrayList.get(ArrayList.java:322)
   at org.hibernate.hql.ast.HqlSqlWalker.postProcessUpdate(HqlSqlWalker.java:390)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:164)
   at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
   at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
   at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:388)
   at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:291)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1005)


Update sql inside mapping file -
<query name="Request.getUpdateRouterFlag">
<![CDATA[UPDATE REQUEST SET RouterFlag = :inRouterFlag WHERE RequestNumber = :inRequestNumber]]>
</query>


Bulk updates are supported by HQL but couldnt find any help regarding how can we specify those SQLs inside a mapping file..

http://www.hibernate.org/hib_docs/v3/re ... tch-direct

Please help!!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 4:56 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
Are you looking for custom sql for insert update delete for a class...
http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#querysql-cud


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 5:06 pm 
Beginner
Beginner

Joined: Tue Jun 21, 2005 1:45 pm
Posts: 38
anar wrote:
Are you looking for custom sql for insert update delete for a class...
http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#querysql-cud



No... This is to avoid using generated Hibernate Update sql for a single object....

I'm looking for a way to specify any type of Update sql(which may affect 1 or more records) inside mapping file..


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 6:00 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
could you post your code/mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 6:52 pm 
Beginner
Beginner

Joined: Tue Jun 21, 2005 1:45 pm
Posts: 38
anar wrote:
could you post your code/mapping.


Code:
<hibernate-mapping>
<class name="Request" table="Request">
          <composite-id name="comp_id" class="RequestPK">
               <key-property name="RequestNumber" column="RequestNumber" type="java.lang.Integer" length="4" />
               <key-property name="POFNumber" column="POFNumber" type="java.lang.Integer" length="11" />
          </composite-id>
          <property name="RequestNumber" column="RequestNumber" type="java.lang.Integer" length="4" lazy="false" insert="false" update="false" />
          <property name="AtWorkID" column="AtWorkID" type="java.lang.Integer" length="10" lazy="true" />
          <property name="AccountID" column="AccountID" type="java.lang.Integer" length="0" lazy="true" />
          <property name="AssemblerID" column="AssemblerID" type="java.lang.String" length="7" lazy="true" />
          <property name="AssignedCertNumber" column="AssignedCertNumber" type="java.lang.String" length="50" lazy="true" />
          <property name="AssignedPolicyNumber" column="AssignedPolicyNumber" type="java.lang.String" length="50" lazy="true" />
           ..........
           ..........
           ..........
           </class>
           <query name="Request.getUpdateRouterFlag">
           <![CDATA[UPDATE REQUEST SET RouterFlag = :inRouterFlag WHERE RequestNumber = :inRequestNumber]]>
           </query>
</hibernate-mapping>

     


Code:
Query qry = session.getNamedQuery(id);
String params[] = qry.getNamedParameters();
if(params!=null)
{
      for(int i=0; i<params.length; i++)
      {
            Object paramVal = data.get(params[i]);
            qry.setParameter(params[i], paramVal);
       }
}
rowsUpdated = qry.executeUpdate();


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 8:21 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
when I run this...I get the exception...
No class Def found for REQUEST, confirming that the class name is case sensitive for Hql and should be Request.

Your exception is not that. Makes me wonder if the right query is being loaded in

Query qry = session.getNamedQuery(id);


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 8:49 pm 
Beginner
Beginner

Joined: Tue Jun 21, 2005 1:45 pm
Posts: 38
anar wrote:
when I run this...I get the exception...
No class Def found for REQUEST, confirming that the class name is case sensitive for Hql and should be Request.

Your exception is not that. Makes me wonder if the right query is being loaded in

Query qry = session.getNamedQuery(id);


Anar,
You are the man... !!!

That was the problem...... damn.. i should have thought of that... i had turned off the logging so didnt see the message "No mapping found for REQUEST"

Well, thanks a lot!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.