JPA @Embedded and @Embeddable
  • bloo November 2011

    Is there an easy way to define a "composite" association between two JPA1 entities which will create one as an @Embeddable object to its "parent"? In an effort to duplicate what the example class diagram contains (UML Lab Shop Example), I tried to "Edit Association" from the default "Composition" association line to remove "Navigable" option so that the association mimicked that found in the example, but this still did not produce any @Embeddable object related to the @Entity associated.

  • Manuel Bork November 2011

    Hi Bloo,

    That's simple - you just have to apply the "PersistentPart" stereotype on the entity: select the entity and choose the stereotype in the "Stereotypes" tab in the properties view. This stereotype has the UML Property "Part Type". "Embeddable" is the default value of that property.

    The Association itself must be a uni-directional composition (to 1), as you already descriped. I attached a screenshot of how the complete pattern should look like.

    Best regards
    Manuel

  • Manuel Bork November 2011

    This is the screenshot I mentioned.

  • bloo November 2011

    Hi Manuel,

    I don't see the screenshot attached, but I added the Stereotype and it worked as you described. Thanks for the response!

    -B

  • Manuel Bork November 2011

    Uh, it seems my internet connection did not manage to submit the screenshot (I was in a train)... Glad it worked nevertheless.

    Attachments
    EmbeddableExample.png (4K)

Welcome!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

In this Discussion