6 Replies Latest reply on Jul 15, 2005 12:06 AM by epbernard

    Mapping composite keys

    doofus

      All,

      I have a composite primary key class, annotated as @Embeddable, and i wish to use this as the id of my entity. In Preview 5 I used the following code:

      @EmbeddedId({
       @AttributeOverride(name="col1"),
       @AttributeOverride(name="col2")
      })
      


      This used to work perfectly. In beta 1 i get this error:


      The attribute value is undefined for the annotation type EmbeddedId


      I am almost positive that all required libraries are on the classpath. I can get everything to work by simply omitting the @AttributeOveride annotations in this case but this may not always be the case (?) i am guessing.

      Any thoughts ...?

      Also, as a side thought, is it possible when generating these errors to show more clearly what parts of the error are related to the syntax of EJB and what is just descriptive. What the error above, i am assuming, means is actually this:


      The attribute 'value' is undefined for the annotation type 'EmbeddedId'


      I dont know if it is just my IDE (eclipse) or an actual error message from within the libraries though. Sorry if it is the former.

      Thanks again ..

      -luke

        • 1. Re: Mapping composite keys
          gommo

          Column name is a class and not a string. i.e.

          @EmbeddedId({
          @AttributeOverride(name="invoice",column={@Column(name="invoice_id")}),
          @AttributeOverride(name="order",column={@Column(name="order_id")})
          })

          • 2. Re: Mapping composite keys
            gommo

            Sorry, my bad, your not even specifying columns

            • 3. Re: Mapping composite keys
              elkner

              NOTE: @EmbeddedId does not take any arguments/parameters in the recent EJB3beta anymore ...

              • 4. Re: Mapping composite keys
                doofus

                should the tutorials be updated? i gather many people will use this as a starting point.

                also, is there any java doc on this. i searched for a fair while before posting this message, as i had suspicions that it might have been changed in beta 1, yet i could not find whether this was the case, nor any documentation on the persistence libraries. it is also not on the 'migrating to beta 1' wiki entry. that is a little frustrating.

                so, now that we have established that they are not part of the standard any more what is the new approach?

                lastly, can we have a complete list of what HAS changed since preview 5?

                thanks,

                -luke

                • 5. Re: Mapping composite keys
                  ploskikl

                  I have the exact problem as described at the start of this topic and would also appreciate some help.

                  I was able to find some documentation for composite keys in Beta 1.

                  Go to
                  http://hibernate.org/~emmanuel.doc

                  and scroll down to section 4.3, Mapping identifier properties

                  At the end of section 4.3 it says:

                  You can define a composite primary key through several syntaxes:
                  - annotate the component property as @Id and make the component class @Embeddable
                  - annotate the component property as @EmbeddedId
                  - annotate the class as @IdClass (This mapping is currently not supported by the implementation).
                  Have a look at Child.java and Parent.java for some examples.

                  "Child.java" and "Parent.java" are both hyperlinks. However, when I click on either link (in Internet Explorer), I receive

                  The page cannot be found.

                  Could some one please fix the links so that we can view the source code?

                  Thank you very much!
                  - Karen

                  • 6. Re: Mapping composite keys
                    epbernard

                    http://annotations.hibernate.org for the up to date doc