-->
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: Problem with xdoclet tag '@hibernate.many-to-one cascade'
PostPosted: Wed May 11, 2005 8:08 am 
Regular
Regular

Joined: Fri Feb 25, 2005 3:02 am
Posts: 71
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

[b]Hibernate version:3.0[/b]

[b]Mapping documents:
User.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
>
<class
name="com.gloptv.smsc.User"
table="smsc_user"
lazy="false"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
>

<id
name="id"
column="id"
type="int"
>
<generator class="sequence">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-User.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<property
name="name"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="name"
not-null="true"
/>

<property
name="description"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="description"
/>

<property
name="password"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="password"
not-null="true"
/>

<property
name="isAdmin"
type="boolean"
update="true"
insert="true"
access="property"
column="is_admin"
not-null="true"
/>

<property
name="loginDate"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="login_date"
/>

<property
name="lockedDate"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="locked_date"
/>

<property
name="lastIp"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="last_ip"
/>

<set
name="customers"
lazy="false"
inverse="true"
cascade="all"
sort="unsorted"
order-by="name"
>

<key
column="user_id"
>
</key>

<one-to-many
class="com.gloptv.smsc.Customer"
/>

</set>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-User.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>

Customer.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
>
<class
name="com.gloptv.smsc.Customer"
table="customer"
lazy="false"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
>

<id
name="id"
column="id"
type="int"
>
<generator class="sequence">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Customer.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<property
name="name"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="name"
not-null="true"
/>

<many-to-one
name="user"
class="com.gloptv.smsc.User"
cascade="all"
outer-join="auto"
update="true"
insert="true"
access="property"
column="user_id"
not-null="true"
/>

<set
name="keywords"
lazy="false"
inverse="true"
cascade="all"
sort="unsorted"
order-by="name"
>

<key
column="customer_id"
>
</key>

<one-to-many
class="com.gloptv.smsc.Keyword"
/>

</set>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Customer.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>

[/b]

[b]Code between sessionFactory.openSession() and session.close():[/b]

[b]Full stack trace of any exception that occurs:[/b]

[b]Name and version of the database you are using:postgresql 8.0[/b]

[b]The generated SQL (show_sql=true):[/b]

[b]Debug level Hibernate log excerpt:[/b]

Hi, my problem is that when I do an schemaexport in order to create the tables, I found that although I specified 'cascade=all' in both cases, the constraint generated in table customer is as follows:

CONSTRAINT fk24217fde22d95c25 FOREIGN KEY (user_id) REFERENCES smsc_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION.

I think that it sould be like this:

CONSTRAINT fk24217fde22d95c25 FOREIGN KEY (user_id) REFERENCES smsc_user (id) ON UPDATE CASCADE ON DELETE CASCADE.

In fact what I want is that if I delete a user, all customers associated to this user should be deleted and if I update a user all customers associated to this user should be updated. And now if I delete/update a customer nothing should happen to the user.

please help
thanks in advance


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.