aspose file tools*
The moose likes Object Relational Mapping and the fly likes insert two tables in single action ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "insert two tables in single action ?" Watch "insert two tables in single action ?" New topic
Author

insert two tables in single action ?

Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223
i am using struts with hibernate

i am using mssql2000 server. i have 2 tables

1. displayname (FieldID,Title)
2. MainTable (FieldID, Description)


i have one jsp. it contains title and description

i want to insert title, in the first table(displayname, see above) and
i want to insert description, in the second table(mainTable, see above)

Could you tell me the in single submission, i want to insert two databases.

How Hibernate Query looks like. thanks
Thanks
edward


Thank You<br />Edward
Reza Ravasizadeh
Ranch Hand

Joined: Jun 08, 2004
Posts: 177
make store procedure at database side (T-sql in SQL server if I remember correctly )and call that store procedure in hibernate(should be possible I'm not aware about Hibernate)


Reza
Raminder Singh
Ranch Hand

Joined: Mar 01, 2002
Posts: 72
for two tables say u have 2 hbm files(t1,t2) and 2 java persistance files(p1,p2)
now while saving, write:

.......
session.save(p1);
.......
......
session.save(p2);
tx.commit();

Call commit() whne u have saved objects of both classes representing ur tables.

hope it works......!!!
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
@Raminder:
i think edward wants to insert two entries with the same FieldId ??
with your aproach hibernate will use two different IDs (unless you use "assigned" generator.

so probably you need to map the properties (Title, Description) of your class to two tables. in hibernate you use the <join> element for this.

perhaps you could also use a one-to-one relation with primary key association could do the trick if its a composition (you did not show any code...)

check the hibernate reference manual for those two things and see if they help...

pascal
 
Don't get me started about those stupid light bulbs.
 
subject: insert two tables in single action ?