Hello,
My setup is JBoss 3.2.1, with Hibernate 2.03 installed as an MBean running against MS SQLServer 8. All Hibernate calls are actioned through Session EJBs with CMT, the Hibernate session being closed at the end of each EJB method invocation.
We've got a one-to-one relationship set up as follows:
Code:
default-cascade="none"
<class name="com.psi.User" table="UserTable">
<id name="id" column="id" type="long" unsaved-value="null">
<generator class="native"/>
</id>
<property name="name" type="string" unique="true"/>
<property name="password" type="string"/>
<joined-subclass name="com.psi.Customer" table="Customer">
<key column="id"/>
<many-to-one name="company"
column="company"
class="com.psi.Company"/>
<one-to-one name="Account" class="com.psi.Account" />
</joined-subclass>
</class>
<class name="com.psi.Account" table="Account">
<id name="id" column="id" type="long" unsaved-value="null">
<generator class="foreign">
<param name="property">Customer</param>
</generator>
</id>
<property name="name" type="string"/>
<one-to-one name="Customer" class="com.psi.Customer" />
</class>
What we're attempting to do is add new (transient) Account to an already existing Customer, and then save it via a session bean call. What actually happens is that Hibernate attempts to create a new instance of Customer on the database, which fails because of the unique constraint on Customer.name. If the constraint is remove we get multiple duplicate rows.
Our current none-working code looks like this:
Code:
{
...
customer.setAccount(account);
account.setCustomer(customer);
...
}
{
//ejb method
...
session.saveOrUpdate(account);
session.flush;
session.close;
...
}
I've tried various combinations of composition and bean saving, but mthing has made any difference. Can anyone shed any light on this, please?
Will