Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3.0
Mapping documents:Person.hbm.xml, Address.hbm.xml
Code between sessionFactory.openSession() and session.close():Using HibernateTemplate and HibernateTransactionManager
Full stack trace of any exception that occurs:-
Name and version of the database you are using:MySQL 4.1
The generated SQL (show_sql=true):-
Debug level Hibernate log excerpt:
Hi,
my hibernate mappings:
Address.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="ebooking.module.base.bean.address.Address" table="BASE_ADDRESS">
<id name="id" type="long">
<column name="ID" not-null="true"/>
<generator class="increment"/>
</id>
<property name="street" type="string">
<column name="STREET" length="100" not-null="false"/>
</property>
<property name="zipCode" type="string">
<column name="ZIPCODE" length="25" not-null="false"/>
</property>
<property name="city" type="string">
<column name="CITY" length="100" not-null="false"/>
</property>
<property name="countyId" type="long">
<column name="COUNTY_ID" length="100" not-null="false"/>
</property>
<property name="countryId" type="long">
<column name="COUNTRY_ID" length="100" not-null="false"/>
</property>
<property name="stateId" type="long">
<column name="STATE_ID" length="100" not-null="false"/>
</property>
<property name="postalName" type="string">
<column name="POSTAL_NAME" length="100" not-null="false"/>
</property>
<property name="department" type="string">
<column name="DEPARTMENT" length="150" not-null="false"/>
</property>
<property name="phone1" type="string">
<column name="PHONE1" length="100" not-null="false"/>
</property>
<property name="phone2" type="string">
<column name="PHONE2" length="100" not-null="false"/>
</property>
<property name="telefax" type="string">
<column name="FAX" length="100" not-null="false"/>
</property>
<property name="mobilePhone" type="string">
<column name="MOBILE_PHONE" length="100" not-null="false"/>
</property>
<property name="email" type="string">
<column name="EMAIL" length="100" not-null="false"/>
</property>
<property name="www" type="string">
<column name="WWW" length="150" not-null="false"/>
</property>
<set name="persons" table="BASE_PERSON" inverse="true" cascade="all" lazy="true">
<key column="ADDRESS_ID"/>
<one-to-many class="ebooking.module.base.bean.person.Person"/>
</set>
<!--
<set name="persons" table="BASE_PERSON_ADDRESS" cascade="all">
<key column="ADDRESS_ID" not-null="true"/>
<many-to-many class="ebooking.module.base.bean.person.Person">
<column name="PERSON_ID"/>
</many-to-many>
</set>
-->
</class>
<class name="ebooking.module.base.bean.address.Country" table="BASE_ADDRESS_COUNTRY">
<id name="id" type="long">
<column name="ID" not-null="true"/>
<generator class="increment"/>
</id>
<property name="name" type="string">
<column name="NAME" length="100" not-null="true"/>
</property>
<!--
<set name="counties" table="BASE_ADDRESS_COUNTY" cascade="all">
<key column="ADDRESS_COUNTRY_ID"/>
<one-to-many class="ebooking.module.base.bean.address.County"/>
</set>
-->
</class>
<class name="ebooking.module.base.bean.address.County" table="BASE_ADDRESS_COUNTY">
<id name="id" type="long">
<column name="ID" not-null="true"/>
<generator class="increment"/>
</id>
<property name="name" type="string">
<column name="NAME" length="100" not-null="true"/>
</property>
</class>
</hibernate-mapping>
Person.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="ebooking.module.base.bean.person.Person" table="BASE_PERSON">
<id name="id" type="long">
<column name="ID" not-null="true"/>
<generator class="increment"/>
</id>
<property name="titleId" type="long">
<column name="TITLE" not-null="false"/>
</property>
<property name="academicTitleId" type="long">
<column name="ACADEMIC_TITLE" not-null="false"/>
</property>
<property name="firstname" type="string">
<column name="FIRSTNAME" not-null="false"/>
</property>
<property name="lastname" type="string">
<column name="LASTNAME" not-null="false"/>
</property>
<many-to-one name="address" column="ADDRESS_ID" class="ebooking.module.base.bean.address.Address" cascade="all"/>
<!--
<set name="addresses" table="BASE_PERSON_ADDRESS" cascade="all">
<key column="PERSON_ID" not-null="true"/>
<many-to-many class="ebooking.module.base.bean.address.Address">
<column name="ADDRESS_ID"/>
</many-to-many>
</set>
-->
</class>
<class name="ebooking.module.base.bean.person.Title" table="BASE_PERSON_TITLE">
<id name="id" type="long">
<column name="ID" not-null="true"/>
<generator class="increment"/>
</id>
<property name="title" type="string">
<column name="TITLE" length="50" not-null="true"/>
</property>
</class>
<class name="ebooking.module.base.bean.person.AcademicTitle" table="BASE_PERSON_ACADEMIC_TITLE">
<id name="id" type="long">
<column name="ID" not-null="true"/>
<generator class="increment"/>
</id>
<property name="academicTitle" type="string">
<column name="ACADEMIC_TITLE" length="100" not-null="true"/>
</property>
</class>
</hibernate-mapping>
My goals is to have a person with one address and an address can contain many persons. Now if i delete a person all other persons with this address will be deleted too. I don't want that. The address should be deleted if no more persons exist with this address.
Thanks