Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

insert two tables in single action ?

 
Edward Durai
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Reza Ravasizadeh
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Raminder Singh
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic