Polymorphic associations with Hibernate and Relational Database


#1

Hi,

Sorry if my questions isn’t refer only to the Hibernate but also to modeling issues, but I think there isn’t better place to ask and get a good answer.

I’m using PostgreSQL with Hibernate, and I’m trying to model a table of stock transactions, it’ll register in and out of products.

My issue is: a lot of different process will produce these transactions, e.g.: an order, sell and others…

How could I create my associations and references to make “easier” to Hibernate mapping and get the best of Hibernate in this case?

Should I have a field per association on table, consequently an attribute per association on my entity? Or is there a better way?

Thanks in advance.


#2

Single table inheritance performs the best when it comes to performance.

Also, make sure you use a compact discriminator column as well.