7 Replies Latest reply on Sep 21, 2005 8:55 AM by epbernard

    Composite ID's

    weegeptr

      Hello.
      Im from Brasil. (They forgive my difficulty with English)
      I have any questions about Composite ID's with EJB3

      When i have a composite ID case, is it possible Annotate 2 or more getters with @Id or is necessary to create a PrimaryKey class and use EmbeddedId?

      Thanks
      Patrick Weege

        • 1. Re: Composite ID's
          epbernard

          @IdClass

          • 2. Re: Composite ID's

            Which is better and why? IdClass or EmbeddedId

            • 3. Re: Composite ID's
              epbernard

              This does not do the same thing, look at the doc.

              • 4. Re: Composite ID's

                 

                "epbernard" wrote:
                This does not do the same thing, look at the doc.


                The IdClass annotation is used to denote a composite primary key.
                
                The EmbeddedId annotation is used to denote a composite primary key that is an embeddable class.
                


                It's hard to tell from the docs. It looks like either can be used for composite keys, but if the composite key is comprised of foreign key(s) you have to use the embeddedId tag. If not, I do not understand what an embeddable class is.

                Is this correct?


                • 5. Re: Composite ID's
                  epbernard

                  @IdClass means the @Entity will have the pk properties in the class itself.
                  @EmbeddedId means the @Entity will have a composition link between itself and the @embeddable class. The embeddable class will have the pk properties.

                  • 6. Re: Composite ID's

                     

                    "epbernard" wrote:
                    @IdClass means the @Entity will have the pk properties in the class itself.
                    @EmbeddedId means the @Entity will have a composition link between itself and the @embeddable class. The embeddable class will have the pk properties.


                    Does the @IdClass support composite primary keys made up of foreign keys any better than @EmbeddedId does?

                    • 7. Re: Composite ID's
                      epbernard

                      no