Hibernate version: 2.1
Name and version of the database you are using: Firebird 1.5
hi,
i did some exercises with hibernate and i am content with the most functions of hibernate. today i want to tried an many-to-many association with additional attributes, as i had problems i tried to find answers in the documentation and here. but i still have a problem:
I have two classes: Employee (that is a subclass of person) and Publication. Between this 2 classes there is an association class Emp_Pub. I modelled this association class as it is told in the documentation, but now i have problems in creating objects - i think there is a fault in my java-class Emp_Pub
Person.hbm.xml
Code:
<class name="Person"
table="PERSON"
lazy="true">
<id name="pId"
type="long"
column="PID">
<generator class="native"/>
</id>
...
<joined-subclass name="Employee"
table="EMPLOYEE"
lazy="true">
<key column="PID"/>
<property name="education"
type="string"
column="EDUCATION"
length="20"
not-null="true"
update="true"/>
<many-to-one name="department"
class="Department"
cascade="all"
not-null="true"
column="DEPART_ID"
update="true"/>
<set name="publications" table="EMP_PUB">
<key foreign-key="FK_EMPLOYEE_PID" column="EMPLOYEE_PID"/>
<composite-element class="Employee_Pub">
<property name="created" type="date"/>
<many-to-one name="publication" foreign-key="FK_PUBLICATION_ID" column="PUBLICATION_PUBID" not-null="true"/>
</composite-element>
</joined-subclass>
...
</class>
Publication.hbm.xml
Code:
<class name="Publication" table="PUBLICATION">
<id name="pubId" column="PUBID" type="long">
<generator class="increment"/>
</id>
<property name="title" column="TITLE" type="string"/>
<property name="publicated" column="PUBLICATED" type="boolean"/>
<set name="employees"
inverse="true"
lazy="true"
table="EMP_PUB"
cascade="all">
<key>
<column name="PUBLICATION_PUBID" not-null="true"/>
</key>
<many-to-many class="Employee">
<column name="EMPLOYEE_PID" not-null="true"/>
</many-to-many>
</set>
</class>
Employee_Pub.java
Code:
public class Employee_Pub {
private Date created;
private Employee employee;
private Publication publication;
... getter & setter
now to my problem: how must the Employee_Pub.hbm.xml file musst looke like, i made some tries, but nothing worked.
thanks for helping, sorry that my english is not the best