Skip to content

hibernate inheritance

inheritance is a well known part of polymorphism in any object orientated language. To map something like an abstract class called “Customer” which has two subcalsses called “PrivateClient” and “CompanyClient” you have three different choices which are well documented in the hibernate docs (table-per-class, …).

When you retrieve the class from the database by runtime, hibernate dosen’t load the real subclass just the superclass, until it gets loaded in deph. By default the lazy loading method does that.

Turning off lazy loading on the superclass in the mapping file prevents loading only the superclass, enabling to cast the superclass to a subclass sucssesfully.

I don’t really like trying with the keyword “instancof” to check which subclass it is, so my roommate pointed me to the “Visitor Pattern” but i don’t really understand it jet. In my future Postings I will include it.

Categories: AppFuse.

Tags: , , , ,

Comment Feed

No Responses (yet)



Some HTML is OK

or, reply to this post via trackback.