-->
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: foreign keys setup question
PostPosted: Sat Jul 19, 2008 2:00 am 
Newbie

Joined: Sat Jul 19, 2008 1:49 am
Posts: 1
I am somewhat stuck adding a FK constraint via hibernate and thus seeking help/feedback. At first the problem seemed simple: hibenate mappings listed below; the tables will be populated with data from a script, so needed FK to ensure data integrity. I planned to use hibernate only to read data into beans. The fields in the Java classes match columns in the tables.

<class name="FirstBean" table="FirstTable">
<id name="ContextId" />
[other fields…]
</class>

<class name="SecondBean" table="SecondTable">
<composite-id>
<key-property name="ContextId" />
<key-property name="ConceptTypeId" />
[ …]
</composite-id>
[other fields…]
<!-- add a fk contstraint for context id -->
<many-to-one name="ContextId" class="FirstBean" column="ContextId" insert="false" update="false" />
</class>

The database tables were created just fine with the FK in place. However, my unittests were failing with "ERROR BasicPropertyAccessor - expected type: int, actual value: ....FirstBean$$EnhancerByCGLIB$$746d0718

So, the hibernate tried to retrieve a proxy(?) to a FirstBean while populating SecondBean object. That was not my intent at all.. Ok, next I changed <many-to-one> directive to give it a new name
<many-to-one name="FKContextId" class="FirstBean" column="ContextId" insert="false" update="false" />
However, while the database was again created just fine, the tests failed because a “getter” for FKContextId was not found in a bean.

I finally added a required property to the bean and things worked:
private Object fkContextId;
public void setFKContextId(Object o){
this.fkContextId=o;
}
public Object getFKContextId(){
return this.fkContextId;
}

Yet, this pollutes bean object with junk... Is there any way to add a simple FK constraint??

Many thanks in advance for your help!


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.