Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
I am fairly new to complex mappings in hibernate, and I can't find a good example that does what I am attempting to do. I have a set of 3 tables as follows:
Code:
KYCCHECK (
ID int
);
QUERY_RESULT (
ID int,
QSCOMPONENT_ID int not null,
CHECK_ID int not null,
RESULT LONGVARCHAR
);
QSCOMPONENT (
ID int not null,
NAME varchar(100) not null,
);
Where QUERY_RESULT.CHECK_ID is the foreign key of KYCCHECK.ID and QUERY_RESULT.QSCOMPONENT_ID is the foreign key of QSCOMPONENT.ID.
As you can see from my mapping below, i have a map called resultMap which contains the QSCOMPONENT.ID field as the key and the QUERY_RESULT.RESULT as the value. I'd like to have the foreign key be used in the map so that the key value is actually the string value of QSCOMPONENT.NAME instead of the ID.
Is this possible?
Thanks,
Jason
Hibernate version: 3.0.1
Mapping documents:Code:
<?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>
<class name="com.semagix.apps.ciras.model.KYCCheck" table="KYCCheck">
<id name="id" column="ID">
<generator class="native"/>
</id>
<map name="resultMap" table="QUERY_RESULT" lazy="false" order-by="QSCOMPONENT_ID asc">
<key column="CHECK_ID"/>
<map-key type="string" column="QSCOMPONENT_ID"/>
<element type="string" column="RESULT"/>
</map>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
session.get(KYCCheck.class, new Long(964));
Name and version of the database you are using:HSQLDB 1.7.2
The generated SQL (show_sql=true):Code:
Hibernate: select kyccheck0_.ID as ID0_, kyccheck0_.TIMESTAMP as TIMESTAMP12_0_, kyccheck0_.LAST_ID as LAST3_12_0_, kyccheck0_.REVIEW_COMPLETED as REVIEW4_12_0_ from KYCCheck kyccheck0_ where kyccheck0_.ID=?
Hibernate: select input0_.CHECK_ID as CHECK1___, input0_.VALUE as VALUE__, input0_.PARAM as PARAM__ from KYCINPUT input0_ where input0_.CHECK_ID=?
Hibernate: select resultmap0_.CHECK_ID as CHECK4___, resultmap0_.RESULT as RESULT__, resultmap0_.QSCOMPONENT_ID as QSCOMPON3___ from QUERY_RESULT resultmap0_ where resultmap0_.CHECK_ID=? order by resultmap0_.QSCOMPONENT_ID asc
Hibernate: select results0_.CHECK_ID as CHECK4___, results0_.ID as ID__, results0_.ID as ID0_, results0_.result as result13_0_, results0_.QSCOMPONENT_ID as QSCOMPON3_13_0_ from QUERY_RESULT results0_ where results0_.CHECK_ID=?
Hibernate: select history0_.CHECK_ID as CHECK6___, history0_.ID as ID__, history0_.ID as ID0_, history0_.ACTION as ACTION15_0_, history0_.COMMENTS as COMMENTS15_0_, history0_.STATUS as STATUS15_0_, history0_.TIMESTAMP as TIMESTAMP15_0_ from KYCCHECKINFO history0_ where history0_.CHECK_ID=? order by history0_.id