-->
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.  [ 4 posts ] 
Author Message
 Post subject: Insertion problem in Hibernate
PostPosted: Fri Jul 21, 2006 1:17 am 
Beginner
Beginner

Joined: Thu Jul 13, 2006 10:39 am
Posts: 23
Hi all,

I have two tables submission and application. Submission.hbm file

contains <many-to-one> tag element for relationship.

How wiil I insert a new record in child table using Hibernate?.


My table structure looks like this:

-------------------------------------
Submission

submission_id raw primary key
application_id raw foriegn key
submission_name varchar
created_ts date

Application

applicaion_id raw primary key
appication_name varchar
application_path varchar
created_ts Date
--------------------------------------------------------------

my hbm files looks like this:
------------------------------------------
Submission.hbm file

<class name="Submissions" table="submission">

<id name="submissionId" type="string" unsaved-value="null" >
<column name="submission_id" sql-type="raw(16)" not-null="true"/>
</id>

<property name="subName">
<column name="submission_name" sql-type="varchar(50)" not-
null="true"/>
</property>

<property name="createdTs">
<column name="created_ts" sql-type="Date" not-null="true"/>
</property>

<many-to-one name="application" insert="false" update="false"
class="Application" column="application_id" />
</class

application.hbm file

<class name="Application" table="application">

<id name="appId" type="string" unsaved-value="null" >
<column name="application_id" sql-type="raw(16)" not-null="true"/>
</id>

<property name="appName">
<column name="application_name" sql-type="varchar2(100)" not-
null="true"/>
</property>

<property name="appPath">
<column name="application_folder_name" sql-type="varchar2
(2000)" not-null="true"/>
</property>

<property name="createdTs">
<column name="created_ts" sql-type="date" not-null="true"/>
</property>

<set name="submissions" inverse="false" cascade="all-delete-
orphan">
<key column="application_id"/>
<one-to-many class="Submissions"/>
</set>

</class>

------------------------------------------------------
My question how to insert a new record into Submission table not
Application table


Can anyone please help me to solve this issue

Thanks and regards,
Sreekanth


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 21, 2006 9:42 am 
Newbie

Joined: Wed Oct 12, 2005 11:17 am
Posts: 7
Let me see if I get this right....

You have a foreign key from the submission table to the application table. You're asking how to insert into the submission table withouth inserting into the application table.

How is the submission.application_id field supposed to be populated? You have stated that it cannot be null and that any value in this field must exist in the application_id field in the application table.

I think you need to re-think what you're saying. You should be able to "pretend" to be Hibernate. It's only SQLs, right? In this situation, how would you insert into the submission table using a SQL? If that can be explained, then you might be closer to an answer here.


Top
 Profile  
 
 Post subject: Insertion problem
PostPosted: Mon Jul 24, 2006 12:24 am 
Beginner
Beginner

Joined: Thu Jul 13, 2006 10:39 am
Posts: 23
Hi,

thank u for ur favourable reply.

I don't know my hbm file declarations are correct. But the table structure is correct. I have not decalred any property for application_id in Submission.hbm.xml file.But I have given <set> tag in application.hbm file and <many-to-one> tag element in submission table. In submission.java bean file , I have created Application object setter and getter methods.

But I need to insert record into submission table without insert into application table.Also I need to fetch application details of a particular submission. application_id

Is there any solution? If so, Please send me the code and hbm fle proper declarations.

Thanks and regards,
Sreekanth.


aphawkes wrote:
Let me see if I get this right....

You have a foreign key from the submission table to the application table. You're asking how to insert into the submission table withouth inserting into the application table.

How is the submission.application_id field supposed to be populated? You have stated that it cannot be null and that any value in this field must exist in the application_id field in the application table.

I think you need to re-think what you're saying. You should be able to "pretend" to be Hibernate. It's only SQLs, right? In this situation, how would you insert into the submission table using a SQL? If that can be explained, then you might be closer to an answer here.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 24, 2006 5:22 am 
Regular
Regular

Joined: Wed May 05, 2004 3:41 pm
Posts: 118
Location: New Jersey,USA
If you are using Application as master table (i.e. read only), how will the "Set" of Application in Submissions be populated.

Should'nt you be loading the "Application" objects via the session.load() or via a Criteria/Query so that you can take those objects and assign them to the Submissions.

Once you have done that you can probably use a "saveorUpdate" call so that Application is never saved and the corresponding "Submissions" is saved.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.