AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Hibernate - Mapping Exception

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases
View previous topic :: View next topic  
Author Message
garhone
Guest





PostPosted: Wed Aug 23, 2006 1:58 am    Post subject: Hibernate - Mapping Exception Reply with quote



Hi,

I'm new to Hibernate and am trying to work out the mapping ... and I'm
hitting a brick wall!!

Call.hbm.xml:
<hibernate-mapping>
<class name="Call" table="call">
<composite-id>
<key-property name="studyId" type="integer" column="study_id" />
<key-property name="phone" type="long" column="phone" />
<key-property name="accessDate" type="date" column="access_date"
/>
</composite-id>
<many-to-one name="studyId" class="Study" insert="false"
update="false">
<column name="study_id" />
</many-to-one>
<property name="callId" type="long" column="call_id"
not-null="true" unique="true" />
</class>
</hibernate-mapping>

Study.hbm.xml:
<hibernate-mapping>
<class name="Study" table="study">
<id name="studyId" column="study_id" type="integer" />
<property name="studyName" column="study_name" type="string" />
</class>
</hibernate-mapping>

Attr.hbm.xml:
<hibernate-mapping>
<class name="Attr" table="attr">
<composite-id>
<key-property name="attrId" type="long" column="attr_id" />
<key-property name="callId" type="long" column="call_id" />
</composite-id>
<property name="attrValue" type="string" column="attr_value" />
<many-to-one name="attrId" class="AttrType" insert="false"
update="false">
<column name="attr_id" />
</many-to-one>
<many-to-one name="callId" class="Call" insert="false"
update="false">
<column name="call_id" />
</many-to-one>
</class>
</hibernate-mapping>

StudyAttrType.hbm.xml
<hibernate-mapping>
<class name="StudyAttrType" table="study_attr_type">
<composite-id>
<key-property name="attrId" type="long" column="attr_id" />
<key-property name="studyId" type="integer" column="study_id" />
</composite-id>
<many-to-one name="studyId" class="Study" update="false"
insert="false">
<column name="study_id" />
</many-to-one>
<many-to-one name="attrId" class="AttrType" update="false"
insert="false">
<column name="attr_id" />
</many-to-one>
</class>
</hibernate-mapping>

AttrType.hbm.xml:
<hibernate-mapping>
<class name="AttrType" table="attr_type">
<id name="attrId" column="attr_id" type="long">
<generator class="sequence">
<param name="sequence">attr_attr_id_seq</param>
</generator>
</id>
<property name="attrName" column="attr_name" type="string" />
</class>
</hibernate-mapping>

Basically, I'm getting an error because of the mapping between Attr and
Call.
Call has a call_id (unique, not null), but its primary key is
(study_id, phone, access_date).
Attr's primary key is composed of two foreign keys: call_id and
study_id
Attr <-many to one->Call
When I comment out a mapping-resource corresponding to one of these 2
(Call or Attr) in hibernate.cfg.xml, my program runs fine.
When the config file contains both mapping-resources, I get the error:

Exception in thread "main" org.hibernate.MappingException: Foreign key
(FK2DD9F14FF19884:attr [call_id])) must have same number of columns as
the referenced primary key (call [study_id,phone,access_date])
at
org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:86)
at
org.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:51)
at
org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:976)
at
org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:921)
at
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:999)
at com.cc.tdcentral.HibernateTest.main(HibernateTest.java:9)

Can anyone shed some light onto this problem?

Thanks,
C
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases All times are GMT
Page 1 of 1

 
Jump to:  
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
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.