I am new to hibernate and I want to use hibernate to insert the data in database(ORACLE).I have done some search on hibernate and i am able to store data and retrive data from one table.Now in my application we have three table
Table A , B , C
Relationship A - B(1-Many) - one record in A and many records in B for the same record
A - C( 1-1)
How do i use hibernate to insert records in all three tables ? at one go..
Regards,
James [ September 05, 2004: Message edited by: james edwin ]
Regards,
James
Venkat dasari
Ranch Hand
Joined: Nov 12, 2003
Posts: 67
posted
0
hi, I am also new to hibernate..i am still trying to insert records into the database. will you please help me how to do it? Moreover, how to retrieve values from two tables since it returns an object array... for example i have a sample database emp and dept... i want all the details of employees along with their location whose deptno=10...
please do help me regarding this.. Thanking you, Venkat Dasari
Regards,<br />Venkat Dasari<br />SCJP 1.4, SCBCD.
pascal betz
Ranch Hand
Joined: Jun 19, 2001
Posts: 547
posted
0
hi James
you can set a "cascade" mode for each relation: cascades
if you set the correct cascade mode, then hibernate will take care of storing/deleting your related objects.
pascal
pascal betz
Ranch Hand
Joined: Jun 19, 2001
Posts: 547
posted
0
hi Venkat
i think you better post a new question in a new topic.
it is hard to answer such a general question, perhaps you should first read one of the tutorials on hibernat, learn how to insert/query a single object and then do the next step and add relations to your objects.
As a hint for your problem: you can query for objects using HQL. HQL is similar to SQL. if you have a specifi question then dont forget to post the code you have so far.
Thanks will look at that.But while i am running the code for Relation A-C table which is having one-to-one relation.When i am trying to insert the record in both the tables,it giving me error...
HIBERNATE EXCEPTION No persister for: c
In Table A.hbm.xml i am an entry like
<one-to-one name="C" class="C"/>
Can someone put some light,why this error is coming !!!
Regards,
James
james edwin
Ranch Hand
Joined: Nov 22, 2001
Posts: 393
posted
0
Hi All,
I am able to move ahead in coding and do mapping in XML part,But when i run the Code,i get the following error :-
HIBERNATE EXCEPTION Repeated column in mapping for class C should be mapped with insert="false" update="false": QUE_ID
Table A -------------
Que_ID not null Varchar2(10) (PK) CDate not null Date
Table C ------------ Que_ID not null Varchar2(10) (FK) CID not null Varchar2(20)
Is it possible Que_ID name in both table is same ,that's why this error is coming .....
Help needed !!!
Regards,
James [ September 06, 2004: Message edited by: james edwin ]
pascal betz
Ranch Hand
Joined: Jun 19, 2001
Posts: 547
posted
0
can you post the full mapping of C ?
how do you realize the one-to-one mapping (there are two ways, as stated in the hibernate docs) ?