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.