I know, value types have no database identity but does that mean Hibernate cann't create an id for them?
I'm modelling a martial art teacher class. A Teacher has 0..n Graduations.
Code:
class Graduation{
//e.g. "Aikido","Aikikai","2.Dan"
String martialArt,organisation,graduation;
}
Because Graduation is totally dependent on Teacher, it should be a value type. But i have a webpage where a teacher can update his graduation if he got promoted. The natural key for this page would be the
teacherID, the
martialArt and the
organisation, but i wonder if i could give an surrogate id to Graduation just as if it would be an entity?
Code:
@Embeddable
class Graduation{
@ID @GeneratedValue
private Long id;
...
}
I guess
session.get( Graduation.class,id) won't be possible because it's no entity but
session.createQuerry("from Graduation g where g.id=:id") should work, shouldn't it?
/Stephan