-->
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.  [ 5 posts ] 
Author Message
 Post subject: How to update data in multiple tables
PostPosted: Tue Jan 23, 2007 2:00 am 
Newbie

Joined: Wed Jan 10, 2007 12:47 am
Posts: 4
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.0

I have to insert data into multiple tables.
Am getting all the information required to post that data into tables in a single servlet.
But at the time of sessionObj.flush(), it is giving error.

I would be happy if any one give solution for this

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 23, 2007 5:28 am 
Beginner
Beginner

Joined: Mon Sep 04, 2006 7:18 am
Posts: 45
I am not sure I understand what your problem is.

But remember that each POJO (your objects) should refer to each table.
So if you want to insert into multiple tables, you will need to create the objects, put the values in its set methods, and then save it. For instance.

Man man = new Man();
man.setHeight("180");
man.setWeight("88");

"session stuff"

session.save(man);

Woman woman = new Woman();
man.setHeight("180");
man.setWeight("88");
"session stuff"

session.save(woman);


Top
 Profile  
 
 Post subject: ok then let me explain clearly
PostPosted: Tue Jan 23, 2007 7:51 am 
Newbie

Joined: Wed Jan 10, 2007 12:47 am
Posts: 4
Am using each POJO for each table. My task is to insert some data into different tables. say for eg i have
student, stud_marks tables
and i have data as
studno:111
studname:XYZ
marks1:22
marks2:33
marks3:44

Now i have to insert this data into those two tables

studno and studname into student table
studno,marks1,marks2,marks3 into stud_marks table.

I used
session.save(studentPOJO);
session.save(studMarksPOJO);
in a single servlet

But it is giving error.
I need solution to this problem.

Hope am clear now


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 23, 2007 8:16 am 
Beginner
Beginner

Joined: Mon Sep 04, 2006 7:18 am
Posts: 45
This is how I store my data.

My utstyr table has a foreign key to kategori.


Code:

session = HibernateUtil.getSessionFactory().getCurrentSession();

       BaatManager baatMgr = BaatkatalogenFactory.getBaatkatalogen().getBaatManager();
       KategoriData kategori = new KategoriData();
       kategori = baatMgr.getKategoriByKnavn("kategori");
//This code above retrieves a Kategori object based on the parameter

       UtstyrData utstyr = new UtstyrData();

       utstyr.setId("" + System.currentTimeInMillis());
       utstyr.setUnavn("utstyr");
       utstyr.setKategori(kategori);
//Here is insert the kategori in utstyr

       session.beginTransaction();
       session.save(utstyr);
//Save when all set methods are finished
       session.getTransaction().commit();


You will have to do similiar. You will need to get the user object based on id or name or something, and then set that in your other object and then save.

Hope this helped.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 23, 2007 8:19 am 
Beginner
Beginner

Joined: Mon Sep 04, 2006 7:18 am
Posts: 45
If you still have problems, paste the stacktrace so we can see the error


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