-->
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: Insert object data in multiple table
PostPosted: Mon Jun 01, 2009 8:04 am 
Newbie

Joined: Mon Jun 01, 2009 7:44 am
Posts: 6
Hi,
I am facing a problem when i try to save one object data into two tables.I am unable to understand how to map these tables in mapping file.
For example:
I have a class Person ,that contain information about Name &Address.
I want to save Name in Name_Table & Address in Address_Table.
How can i do it?


Thanks
SPT


Top
 Profile  
 
 Post subject: Re: Insert object data in multiple table
PostPosted: Mon Jun 01, 2009 8:25 am 
Newbie

Joined: Mon Jun 01, 2009 7:06 am
Posts: 3
I think this is not a mapping problem, but it's a domain problem.

Why you should want to save a Person information in two separate tables instead than in one single table (PERSON_TABLE(person_id, name, address).
Anyway a solution could be to create your own Name/Address class (with just one field, eg: name.content or address.content) and map those ones.
So when you try to store/retrieve a Person object, you also invoke the NameDAO.store operation and store the NAME object in the NAME_TABLE table.


EG:

Code:
Person p = someOfYourMethodToGetAPerson();
Name name = new Name(p.getName());
PersonDAO.store(p);
NameDAO.store(name);


It's not a so elegant solution, but I can't figure out why You should save info in two separate tables.

Regards


Top
 Profile  
 
 Post subject: Re: Insert object data in multiple table
PostPosted: Mon Jun 01, 2009 8:55 am 
Newbie

Joined: Mon Jun 01, 2009 7:44 am
Posts: 6
Thanks ciccio17

I think you are right.
But actually I am using Spring and Hibernate Framework .
I want to save data in both table with an object.
I tried to make Address_Table as a sub class of PERSON_TABLE.
In this case what will be the Person.hbm.xml and Address.hbm.xml?

The reason of doing this is that we can make only one command class in one controller.
I am trying it so that I can make a command class and usig it I can access the other table.


Please guide me.

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: Insert object data in multiple table
PostPosted: Mon Jun 01, 2009 9:11 am 
Newbie

Joined: Mon Jun 01, 2009 7:06 am
Posts: 3
satayprakash wrote:
Thanks ciccio17

I think you are right.
But actually I am using Spring and Hibernate Framework .
I want to save data in both table with an object.
I tried to make Address_Table as a sub class of PERSON_TABLE.
In this case what will be the Person.hbm.xml and Address.hbm.xml?

The reason of doing this is that we can make only one command class in one controller.
I am trying it so that I can make a command class and usig it I can access the other table.


Please guide me.

Thanks in advance.


What I am asking is: Are your ADDRESS_TABLE and NAME_TABLE really necessary in your application?

It's enough to save your whole Person Object in the PERSON_TABLE(person_id, person_name, person_address). Then, if you have to retrieve all the names (and/or all the addresses) you can just run a simple query (select person_name from PERSON_TABLE, select person_address from PERSON_TABLE).

Regards


Top
 Profile  
 
 Post subject: Re: Insert object data in multiple table
PostPosted: Mon Jun 01, 2009 9:23 am 
Newbie

Joined: Mon Jun 01, 2009 7:44 am
Posts: 6
Actually ciccio17 ,
This is not actual tables . These are for example.
I am using large tables in my project thats why i want to use two tables.
Have you any idea to do that.

Thanks


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.