-->
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: unsure of where to look
PostPosted: Tue Sep 13, 2005 4:30 pm 
Newbie

Joined: Tue Sep 13, 2005 4:07 pm
Posts: 5
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.0.3

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:Oracle 8i

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

This is not a request for help debugging, I just don't know what to look for and I was hoping someone here could point me to a section of the manual that addresses my problem. I don't really care to read through the entire manual looking for a piece of functionality that may not even exist.

I am working on a piece of functionality that builds a survey. Each question is a separate object stored in the database and associated to a survey id. Adding new questions is no problem, but removing questions is because I don't know how to tell hibernate that, when I write the object back to the database that it should delete anything not present on the survey. So if I added 3 questions and decided to delete one, I delete it from my object but there is simply nothing done to it in the database when I write it back.

So my object may look something like this:

SurveyX
\-Question1
|-Question2
|-Question3

When I remove question 3 and write it back to the database, it writes:

surveyxid, question1
surveyxid, question2

but since question 3 was already there, when I get the values back, I get:

SurveyX
\-Question1
|-Question2
|-Question3

because it read question 3 because it was already there. Does hibernate have some sort of feature that knows question 3 was on the object and has been removed so it should be removed from the database? If so what is it called and where do I find the reference for how to use it in the manual?

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 13, 2005 5:02 pm 
Beginner
Beginner

Joined: Tue Apr 05, 2005 4:27 pm
Posts: 40
Location: canada
i think your actual problem is that you're updating the survey object when you should be explicitly deleting the question object you wish to remove.

but i suggest you have a look at

http://www.hibernate.org/hib_docs/v3/reference/en/html/collections.html
especially section 7.3.2 bidirectional associations

and

http://www.hibernate.org/hib_docs/v3/reference/en/html/example-parentchild.html
for some examples.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 13, 2005 6:05 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
You might be looking for the cascade="delete-orphan" attribute (I didn't quite understand your problem)?

See http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#objectstate-transitive


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 14, 2005 1:32 pm 
Newbie

Joined: Tue Sep 13, 2005 4:07 pm
Posts: 5
jaime wrote:
i think your actual problem is that you're updating the survey object when you should be explicitly deleting the question object you wish to remove.

but i suggest you have a look at

http://www.hibernate.org/hib_docs/v3/reference/en/html/collections.html
especially section 7.3.2 bidirectional associations

and

http://www.hibernate.org/hib_docs/v3/reference/en/html/example-parentchild.html
for some examples.


Ok, that was what I was thinking I would have to do. I just didn't want to write something separate if there was a way to do it in Hibernate just through the mapping file.

Thanks.


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.