1

Setup: Hibernate 4.0 (JPA 2.0), Java EE 6

I have the following problem: I have a class "HandAttributes" annotated with @Embeddable which holds a lot of boolean attributes. In another class "Person" I want to embed this class twice. The idea is, that the values in the class "Attributes" represent attributes the "Person" can have on its left and right hand.

As far as I understand the possibilites with @AttributeOverride, I could override each attribute in the HandAttributes class and give them a new Column name i.e. "BrokenNailRight" and "BrokenNailLeft". But as I mentioned, there are many of those Attributes, so I would like to rather not override them all explicitly.

Is there a possibility to Override all attributes in the Embeddable class by giving some kind of naming pattern? Like add the String "left" to all columns or anything similar.

I hope the question is understandable and I'm looking forward any ideas you might have!

1 Answer 1

0

Is there a possibility to Override all attributes in the Embeddable class?

I've never heard of something like this and am pretty sure that this is not possible.

Are you sure that you want to embed these objects? This results in a lot of really static code, that might better be written like this:

public class Human {
Hand leftHand;
Hand rightHand;
...
}

or even

public class Alien {
Map<ConnectedBodyPart, Hand> hands
...
}

This should also enable generic versions of getBrokenNails()...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.