• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to insert

 
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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 ]
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

these links might be useful:
hibernate documentaion
external hibernate docs ant tutorials

pascal
 
james edwin
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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) ?


pascal
 
james edwin
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In A.hbm.xml i have an following entry

**********************
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="A" table="a">
<id name="aId" type="string" unsaved-value="null">
<column name="A_ID" sql-type="char(7)" not-null="true"/>
<generator class="assigned"/>
</id>
<property name="ADescX">
<column name="A_DESC_X" sql-type="char(40)" not-null="true"/>
</property>
<one-to-one name="aId" class="C"/>
</class>
</hibernate-mapping>
***********************************************

AND c.hbm.xml is as follows

***********************************************
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="C" table="c">

<id name="cId" type="string" unsaved-value="null">
<column name="c_ID" sql-type="char(7)" not-null="true"/>
<generator class="assigned"/>
</id>
<property name="mailLastSentD">
<column name="MAIL_LAST_SENT_D" sql-type="Date" not-null="true"/>
</property>
<one-to-one name="cId" class="A"/>
</class>
</hibernate-mapping>
************************************************


Regards,

James
 
james edwin
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After lot of trials !!! ONE-2-ONE PROBLEM IS SOLVED.....

BUT I am stuck up in one to many now....

trying hard on that too !!!
 
"Don't believe every tiny ad you see on the internet. But this one is rock solid." - George Washington
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic