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