I have many-to-many relationship:
COMPANY * - * EMPLOYEE
here is CompanyDTO (POJO):
Code:
public class CompanyDTO implements Serializable{
private static final long serialVersionUID = 1L;
private Long company_id;
private String name;
private EmployeeDTO employee;
private String position;
private Long employeeId;
............(getters-setters).............
}
and also ŃompanyDTO.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="CompanyDTO" table="COMPANY" lazy="false"
batch-size="100">
<id name="company_id" column="COMPANY_ID" type="java.lang.Long">
<generator class="native" />
</id>
<property name="name" column="NAME" type="string" />
<property name="employeeId" />
<set name="address_fk" table="COMP_ADR" fetch="join">
<key column="company_id" />
<many-to-many column="ADDRESS_ID" class="AddressDTO" />
</set>
<property name="counEmplForCompany"
formula="(select count(*) from COMP_EMPL s where company_id = s.COMPANY_ID )" />
<join table="COMP_EMPL" inverse="true" optional="true">
<key column="company_id" />
<many-to-one name="employee" column="employee_id" not-null="true" />
<property name="position" type="string"
formula="(select distinct ce.position FROM COMP_EMPL ce WHERE company_id=ce.COMPANY_ID and ce.employee_id=[b]employee_id[/b])" />
</join>
</class>
</hibernate-mapping>
the question is next-
how can I use the employee_id from the related table, to get the proper meaning from table "position", that consist of (company_id[Long], employee_id[Long]) - individual for each [employee 1 - 1 company]