-->
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.  [ 2 posts ] 
Author Message
 Post subject: XML to DB mapping, on delete cascade pb
PostPosted: Wed Jan 14, 2009 12:10 pm 
Newbie

Joined: Wed Jan 14, 2009 11:58 am
Posts: 2
Hello,
I'm new to hibernate. I'm working with XML to Database mapping rather than POJO to database. My database is MySql5.
I have 2 tables, parent and child.
My hibernate configuration file is the following:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/test</property>
<property name="hibernate.connection.username">login</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="parent.hbm.xml"/>
</session-factory>
</hibernate-configuration>

parent.hbm.xml looks like this:

<?xml version="1.0" ?><!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class entity-name="Parent" table="parent" node="parent">
<id name="id_p" column="id_p" node="@id_p" type="int"/>
<property name="name" column="name" node="name" type="string"/>
</class>
<class entity-name="Child" table="child" node="child">
<id name="id_c" node="@id_c" column="id_c" type="int"/>
<property name="name" column="name" node="name" type="string"/>
<many-to-one name="fk_c_p" column="id_p" node="@id_p" entity-name="Parent" embed-xml="false"/>
</class>
</hibernate-mapping>

I want that when I delete a parent, all its children are deleted (on delete cascade).
This can be done when I execute the following sql command

alter table child add foreign key (id_p) references parent (id_p) on delete cascade;

but I want this to be done with the hibernate config file and not an SQL command.

I tried different solutions but can't succeed.
Can anyone help me please?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2009 6:34 am 
Newbie

Joined: Wed Jan 14, 2009 11:58 am
Posts: 2
no idea?


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