-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problems with using property in formula
PostPosted: Tue Jan 19, 2010 4:51 am 
Newbie

Joined: Tue Jan 19, 2010 4:37 am
Posts: 2
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]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.