-
1. Re: Table per class with different ID generators
waynebaylor Nov 25, 2007 6:35 PM (in response to alexg79)one-to-many from the subclass to the root class? why not put the ID in the superclass?
-
2. Re: Table per class with different ID generators
alexg79 Nov 26, 2007 3:23 AM (in response to alexg79)Because I need to have different sequences in subclasses. The root class is Document, and subclasses are SalesInvoice, OrderConfirmation etc that need to have their own numbering schemes.
-
3. Re: Table per class with different ID generators
waynebaylor Nov 27, 2007 5:14 PM (in response to alexg79)hmm, i can imagine problems with the pk. for example, say you have Document with its own pk. when you create SalesInvoice it inherits the pk from Document. if you try to add an additional field to SalesInvoice's pk, hibernate will probably choke because it's not properly defined as a composite pk.
-
4. Re: Table per class with different ID generators
alexg79 Nov 27, 2007 5:22 PM (in response to alexg79)The problem is that I have an Employee object associated with every Document. When the Employee goes away, the link has to be severed. Being able to do that implicitly (with cascade=CascadeType.REMOVE) would be the ideal solution. Right now I have a hack involving a custom annotation, parameter injection and an UPDATE query that fires whenever an Employee is deleted.
Being able to have an association to Document directly would be a much cleaner solution. Document doesn't have its own table so it doesn't need a PK of its own. It'd be great if I could have getId() defined in Document, and override it in subclasses and set @GeneratedValue along with any specific generators there. I don't see any theoretical problems with that approach. -
5. Re: Table per class with different ID generators
waynebaylor Nov 30, 2007 6:49 PM (in response to alexg79)have you tried using @MappedSuperclass then?
-
6. Re: Table per class with different ID generators
alexg79 Nov 30, 2007 7:15 PM (in response to alexg79)You can't have associations to the root class if it's just a MappedSuperClass -- it has to be an entity.