Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate override @transient

Tags:

hibernate

jpa

I have a mapped super class, which has a field that some of the tables in my DB share.

I wish to annotate this field with @Transient so most entities will ignore it, but de-@Transient or un-@Transient it on child entities.

Is this possible?

Thank you, Idob

like image 680
Ido Barash Avatar asked Oct 24 '12 15:10

Ido Barash


1 Answers

You might be able to use the discriminator pattern

http://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/mapping.html

You would have to set up a parent super class and then sub-class it, something like

ClassWithSharedFields
ClassExtensionThatUpdatesCertainFields
ClassExtensionThatReadsCertainFields

Then, ClassExtensionThatReadsCertainFields could specify the field that you don't intend on updating as read only.

This might be a bit of a vague suggestion, so if you want more specific help maybe provide some more concrete examples of how your domain classes need to behave in relationship to your DB.

like image 156
Jason Lowenthal Avatar answered Nov 09 '22 11:11

Jason Lowenthal