-->
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.  [ 2 posts ] 
Author Message
 Post subject: use enum to build a compoiste primary key
PostPosted: Tue Sep 12, 2006 5:10 pm 
Beginner
Beginner

Joined: Mon Aug 22, 2005 9:57 pm
Posts: 27
Dear all

I encounter a problem when i used Enum type for primary key pair
Does anyone have experienc on this ? what is the solution?

<composite-id name="comp_id"
class="RiskGroupPK">
<key-property name="ruleType" column="RULE_TYPE_KEY"
type="RuleTypeUserType">
</key-property>
<key-property name="key" column="KEY"
type="java.lang.String" length="32">
</key-property>
</composite-id>

RiskGroupPK is a primary key pair , it contains enume RuleType and a string key .

I already get exception , but if I only use enum as a normal property. it
works perfect, only when i used enum and other property to combinate as
a primary key name, it will have Exception as below shown

IllegalArgumentException in class:
RiskGroupPK, getter method of property: ruleType
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of RiskGroupPK.ruleType

Any one has idea how to use enum to build a a primary key pair?

Thanks in advance


Top
 Profile  
 
 Post subject: reply
PostPosted: Wed Sep 13, 2006 11:54 am 
Beginner
Beginner

Joined: Mon Aug 22, 2005 9:57 pm
Posts: 27
Problem is :

usually it is ok to use enum to build composite primary key
through your own defined enumUserType . but in below case. it will have problem

For example


Employee : Person is 1:1 ,

Employee refers to Person 's primary Key PersonPK also as its own Primarykey .
then it is ok in Employee.java and Employee.hbm.xml use EmployeePK instead of PersonPK
as below shown

class Person{
PersonPK comp_id;
//......
}

class PersonPK {
//Person 's Composite PrimaryKey
String firstName;
String lastName;
}


Class Employee {
EmployeePK comp_id;

//......
}

class EmployeePK{
// Employee 's Composite PrimaryKey
String firstName;
String lastName;
}

in Employee.hbm.xml

<composite-id name="comp_id"
class="EomployeePK">


But if PersonPK contains the enum type. like

class PersonPK{
familyName firstname;

String givenName;
}

enum familyName{
Laux, Vogel, Schneider,Schmidt,Pah
}

then you should never use try to use EmployeePK in Employee.java or Employee.hbm.xml,
what you should do is in Employee.java use PersonPK ,
in Employee.hbm.xml, also use PersonPK , other wise you will have
Exception for IllegalArgumentException occurred calling getter of PK class

class EmployeePK{
familyName firstname;
String givenName;
}


I know the work-around ,but what is the real reason behind it?
due to false implemention of genaric type of Hibernate ? or false implementation
of Generic class itself? I think through nice implementation of Hibernate layer
could solve this generic type casting problem

Any hints ?


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

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.