• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Enum used for a primary key pair !

 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
walter wang
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 familyname;

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 familyname;
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 ?

[ September 13, 2006: Message edited by: walter wang ]
[ September 13, 2006: Message edited by: walter wang ]
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic