Hello Everyone,
I am trying to create a one-to-many uni-directional relationship between a 'User' entity and a 'PhoneNumber' entity with 'User' at the owning side of the relationship. The 'User' Entity has a compound primary key consisting of a 'username' and 'bsn'.
Code:
public class User implements java.io.Serializable
{
private UserPrimaryKey userPk; // Embedding primary key class directly into the bean class.
private String firstName, middleName, lastName;
....
// Defining one-to-many unidirectional relationship with phone numbers
private List<PhoneNumber> phoneNumbers = new ArrayList<PhoneNumber>();
....
public List<PhoneNumber> getPhoneNumbers()
{ return phoneNumbers;}
public void setPhoneNumbers(List<PhoneNumber> phoneNumbers)
{this.phoneNumbers = phoneNumbers;}
}
Here's the code snippet from orm.xml
Code:
<entity class="nl.myCompany.domain.User" access="PROPERTY">
<attributes>
<embedded-id name="userPk"/>
.....
<one-to-many name="phoneNumbers" target-entity="nl.igz.instellingsrapporten.domain.PhoneNumber" fetch="LAZY">
<join-table name="USER_PHONE_NUMBERS">
<join-column name="userPk"/> <!-- Foreign key mapping to the primary key of the owning side of relationship -->
<inverse-join-column name="PHONENUMBER_ID"/> <!-- Non owning side of the relationship -->
</join-table>
<cascade><cascade-all/></cascade>
</one-to-many>
<transient name="userName"/>
<transient name="bsn"/>
</attributes>
</entity>
<entity class="nl.myCompany.domain.PhoneNumber" access="PROPERTY">
<attributes>
<id name="id">
<generated-value strategy="AUTO"/>
</id>
<!--
The persistence provider will assume any other property (getters-setters in javabeans style) in class
is a persisitence property and map them based on their based name and type.
-->
</attributes>
</entity>
<embeddable class="nl.myCompany.domain.UserPrimaryKey" access="PROPERTY">
<description>
Identify the persistent properties of the embeddable class.
These columns don't change hence should not be included in SQL UPDATE statements.
Make updatable as false.
</description>
<attributes>
<basic name="bsn" optional="false">
<column name="BSN" nullable="false" updatable="false" unique="true" length="9"/>
</basic>
<basic name="loginId">
<column name="LOGIN_ID" nullable="false" updatable="false" unique="true" length="25"/>
</basic>
</attributes>
</embeddable>
As I deploy the ejb 3 jar into jboss application server (version 4.2.3 GA), I encounter the following error.
org.hibernate.AnnotationException: A Foreign key refering nl.myCompany.domain.User from nl.myCompany.domain.PhoneNumber has the wrong number of column. should be 2Any help in this regards would be highly appreciated.
Thanks a lot for your time and efforts in advance.
V