Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
2.1:
Mapping documents:
<hibernate-mapping>
<class name="com.acme.Employee" table="EMPLOYEE">
<id name="employeeId" column="EMPLOYEE_ID" type="long" unsaved-value="null">
<generator class="identity"/>
</id>
<property name="firstName"
column="FIRST_NAME"
type="string"
not-null="true"/>
<property name="lastName"
column="LAST_NAME"
type="string"
not-null="true"/>
<one-to-one name="phone"
class="com.acme.Phone"
cascade="all" />
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="com.acme.Phone" table="PHONE">
<id name="phoneId" column="PHONE_ID">
<generator class="foreign">
<param name="property">employee</param>
</generator>
</id>
<one-to-one name="employee"
constrained="true"
class="com.acme.Employee" />
<property name="phoneNumber" column="PHONENUMBER" type="string" not-null="true" />
<property name="phoneExtension" column="PHONEEXTENSION" type="string" not-null="false" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Using Spring
Full stack trace of any exception that occurs:
Name and version of the database you are using: MySQL 4
My question is if I save an Employee with a phone everything works just fine. I'm trying to delete that phone number off the employee by calling employee.setPhone(null) and then calling saveOrUpdate on the dao method. cascade is set to all for the phone reference. Shouldn't I be able to do this? I don't want to have to delete phone directly if I don't have to.