-->
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.  [ 6 posts ] 
Author Message
 Post subject: Inserting & deleting of data in Hibernate 2
PostPosted: Sun Nov 12, 2006 10:52 pm 
Newbie

Joined: Fri Nov 10, 2006 5:32 am
Posts: 3
Hi! I'm currently working on a project using Hibernate version 2 and MySQL database. Is there a way to insert & delete data? It seems that I can only do select query.

I browse through documentation URL, http://www.hibernate.org/hib_docs/v3/re ... erysql-cud, and it says "Hibernate3 can use custom SQL statements for create, update, and delete operations".

What changes (lib folder or configuration) do I need to modify to upgrade from hibernate 2 to hibernate 3?

Thank you!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 13, 2006 12:21 pm 
Regular
Regular

Joined: Tue Feb 24, 2004 11:42 am
Posts: 56
http://www.hibernate.org/250.html#A6

thats the migration guide and it says "[b][b][b]However, to make migration easier, these methods are still available, via the org.hibernate.classic.Session subinterface. These deprecated methods are:

query execution methods: find(), iterate(), filter(), delete()[/b][/b][/b]"

if it helps please do rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 13, 2006 12:51 pm 
Regular
Regular

Joined: Tue Feb 24, 2004 11:42 am
Posts: 56
Well if you are still keen on hibernate2.0 then here you go. This should help and answer your question so please do rate.

session.delete(String query)
throws HibernateException

OR

session.delete(String query,
Object value,
Type type)
throws HibernateException

OR

seeion.delete(String query,
Object[] values,
Type[] types)
throws HibernateException


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 13, 2006 11:31 pm 
Newbie

Joined: Fri Nov 10, 2006 5:32 am
Posts: 3
Thanks gopalsaha! I appreciate your reply! Let me further explain the situation.. For my project, I use a java file to call a query. See Example below.

In a Java
Query query2 = dbSession.getNamedQuery("xxx.FavStaff.get.favstaff_no");
query2.setString(0,requestStaffNo);
ListIterator results2 = query2.list().listIterator();
vecFStaffNo = new Vector();
while(results2.hasNext()) {
String fStaffNo = (String)results2.next();
vecFStaffNo.add(fStaffNo.trim());
System.out.println("Favourite Staff No: " + fStaffNo);
}


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

<hibernate-mapping>

<class name="xxx.xx.xxxx.data.Fav_Staff" table="FAV_STAFF">
<id name="id" type="string" column="ID">
<meta attribute="finder-method">findByID</meta>
<generator class="uuid.hex" />
</id>
<property name="staff_no" type="string" column="Staff_no"/>
<property name="favstaff_no" type="string" column="FavStaff_no"/>
</class>

<query name="xxx.FavStaff.get.favstaff_no">
<![CDATA[
select fav_staff.favstaff_no
from xxx.xx.xxxx.data.Fav_Staff as fav_staff
where fav_staff.staff_no = ?
]]>
</query>

</hibernate-mapping>

My question is "Is there Insert or delete function in a query"? Can I do something like this in the hbm.xml? Thank you very much!

<query name="xxx.FavStaff.get.favstaff_no">
<![CDATA[
delete fav_staff.favstaff_no
from xxx.xx.xxxx.xxxx.Fav_Staff as fav_staff
where fav_staff.staff_no = ?
]]>
</query>

OR

<query name="xxx.FavStaff.get.favstaff_no">
<![CDATA[
insert into xxx.xx.xxxx.xxxx.Fav_Staff values(1,2)
]]>
</query>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 14, 2006 6:45 am 
Regular
Regular

Joined: Tue Feb 24, 2004 11:42 am
Posts: 56
http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd
this allows query naming and hence i am sure it should work the way you wanted it. Hope this helps


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 10:35 pm 
Newbie

Joined: Fri Nov 10, 2006 5:32 am
Posts: 3
Thanks gopalsaha! I will try it. Thanks!


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