-->
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.  [ 1 post ] 
Author Message
 Post subject: cascading operations and the underlying database
PostPosted: Sat Aug 15, 2009 7:24 pm 
Newbie

Joined: Sat Aug 15, 2009 7:00 pm
Posts: 2
Hi all,

I am new to hibernate and have a question that may appear tirvial to some of you.

I have a uni-directional relationship between User and Phone.
This relation form point of view of the database : each user has many phones and each phone has one user.
And the cascade operation in the database is not defined by me, so i think it will be not to all delete PK rows as it reference FK rows (as the schema genereated automatically for me when running the application ), so i don't know wether the deleting action in the underlying database is either cascade or no-action or just silent. ( I am using HSQL DBMS)

and from point of view of object model : each Phone object has a User Object, and each User object doesn't know about its phones as the following:

class User {
private long id;
private String name;
private String passwd;
// getters and setters goes here
}

class Phone {
private int id;
private String phoneNumber;
private User user;
}

so, In the user mapping, i don't use the set tag, and in the phone mapping, i use the
Code:
<many-to-one tag
name="user"
class="User"
column="user_id"                               <!--  the forigen key  -->
cascasde="all, delete" />


The problem is:
When i am going to delete a user who has a referenced phones in the phone table, i got a hibernate exception.
So, To use cascading operation in Hibernate, should I make the delete action in the underlying database "cascade" , or hibernate overrides the database settings and allow me to cascade deleting even if it is not the DB behaviour????

I hope i could illustrate my problem.
Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.