See my following mapping xml. Say,I have student table ,course table,book table. And use student_link table to handle many to many mapping. Course and book is many to many mapping through course_book_link table as well. Now I want to add a derived property in Student.java which is defined like:Set<String> bookNames;//which represents all books need for this student
I'm trying on the "formula" with the table join SQL statement. it works fine for single property, but does not work for Set. As you can see, the family is a derived column retrived through formula.
Any idea about this?
Thanks in advance
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.ms.itlnc.dms.workItem.poc.data"> <class name="Student" entity-name="Student" table="Student" > <id name="sid" type="int"> <column name="sid" /> <generator class="native" /> </id> <version name="version"> <column name="VERSION" /> </version> <property name="sname"> <column name="sname" /> </property> <property name="sage"> <column name="sage" /> </property>
<property name="family" type="string" formula="(select f.fname from student_family_link l,family f where l.student_id=sid and l.object_id=f.fid)" />
<set name="courses" > <element type="string" formula="select b.bname from student_link l,course c,course_book_link l2,book b where l.student_id=sid and l.cid=c.cid and c.cid=l2.cid and l2.bid=b.bid" /> </set> </class> </hibernate-mapping>
|