-
1. Re: Problem with TABLE_PER_CLASS inheritance in Preview 5
dsouza Apr 8, 2005 12:59 PM (in response to dsouza)I got it to work by removing all class-level annotations from the superclass and annotating the subclass as a regular entity. I get exactly the same effect I would expect from table_per_class inheritance without explicitly declaring it as such.
I'm glad I found a way to make it work but I still would like to understando what happened.
DS -
2. Re: Problem with TABLE_PER_CLASS inheritance in Preview 5
epbernard Apr 9, 2005 1:47 PM (in response to dsouza)This is the way Hibernate annotations currently implements TABLE_PER_CLASS inheritance. I need to improve that (this is queued)
-
3. Re: Problem with TABLE_PER_CLASS inheritance in Preview 5
bill.burke Apr 11, 2005 8:12 AM (in response to dsouza)you can only put the @Inheritance at the top of the hierarchy. Take a look at Pet, vs. Dog/Cat in the tableperinheritance tutorial
-
4. Re: Problem with TABLE_PER_CLASS inheritance in Preview 5
dsouza Apr 11, 2005 2:12 PM (in response to dsouza)Yes, I had tried that and upon deployment hibernate ended up creating a table mapping for the superclass instead of the child classes. I was running it with hibernate.hbm2ddl.auto=update.
Now that you mentioned it, I tried it again, but this time I dropped all tables and started jboss with hibernate.hbm2ddl.auto=create. It worked. Don't know what I did wrong the first time, though... I guess it should have worked then.
Anyway, thanks for the answer. I wouldn't have tried it again otherwise.
DS -
5. Re: Problem with TABLE_PER_CLASS inheritance in Preview 5
dsouza Apr 11, 2005 2:47 PM (in response to dsouza)Hi, sorry to insist on this, but I started jboss with hibernate.hbm2ddl.auto=update again and the problem came back. If I put the @Inheritance in my superclass, it creates a table in the database with the superclass' name and maps any relationships to it instead of the respective subclasses.
eg. If I have entity A with @Inheritance and entity B extends A, it creates table A in the database. Any relationships from a table C->B are mapped as C->A.
If I remove @Inheritance and leave it as I mentioned before it works fine. If I chose to leave @Inheritance it only works if I start jboss with hibernate.hbm2ddl.auto=create.
It's strange. I wouldn't think changing the automatic table creation option could affect the relationships like that.
DS -
6. Re: Problem with TABLE_PER_CLASS inheritance in Preview 5
dsouza Apr 11, 2005 3:11 PM (in response to dsouza)In hope that it will help to understand and find the problem:
I also was able to make it work in any case once I removed the @Entity from the top of the hierarchy.
As for the @Entity I don't know which exactly is correct, but the tutorial shows that @Entity should be used on both the superclass and the subclass.
In regard to using @Inheritance, the Preview 5 tutorial says that:The subclass annotations look like this. @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public class Dog extends Pet {
The actual Dog class in the tutorial doesn't contain the @Inheritance. I guess it was a typo inherited from the Preview 4 tutorial, but please correct this as it may lead to confusion.
Thanks,
DS