Ido Barash
Ido Barash

Reputation: 5122

Hibernate override @transient

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

Upvotes: 7

Views: 1995

Answers (1)

Jason Lowenthal
Jason Lowenthal

Reputation: 810

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.

Upvotes: 1

Related Questions