Spring Roo
  1. Spring Roo
  2. ROO-505

Need support for @EmbeddedId - a way to specify this in @RooEntity

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Complete
    • Affects Version/s: 1.0.0.RELEASE
    • Fix Version/s: 1.1.0.M3
    • Component/s: PERSISTENCE
    • Labels:
      None
    • Environment:
      Mac OS X -Snow Leopard, Java 6 - 1.6.0_17-b04-248-10M3025, STS 2.3.0

      Description

      I want to use @EmbeddedId in order to use composite primary key. e.g. I want to use the following

      [CODE]
      package com.synconx.entities;

      import java.io.Serializable;

      import javax.persistence.Column;
      import javax.persistence.Embeddable;

      /**

      • @Author Chiradip Mandal
      • @Copyright © Chiradip Mandal 2009
      • @License Apache License v2.0 http://www.apache.org/licenses/LICENSE-2.0
        *
        */
        @Embeddable
        public class EdgeId implements Serializable {
        private static final long serialVersionUID = 7709843884574764331L;
        @Column( name = "SOURCENODEID" )
        private long sourceNodeID;
        @Column( name = "TARGETNODEID" )
        private long targetNodeID;

      public EdgeId() {
      }

      public EdgeId( long sourceNodeID, long targetNodeID )

      { this.sourceNodeID = sourceNodeID; this.targetNodeID = targetNodeID; }

      public long getSourceNodeID()

      { return sourceNodeID; }

      public void setSourceNodeID( long sourceNodeID )

      { this.sourceNodeID = sourceNodeID; }

      public long getTargetNodeID()

      { return targetNodeID; }

      public void setTargetNodeID( long targetNodeID )

      { this.targetNodeID = targetNodeID; }

      @Override
      public boolean equals( Object o ) {
      if ( o instanceof EdgeId )

      { EdgeId that = ( EdgeId ) o; return ( this.sourceNodeID == that.sourceNodeID ) && ( this.targetNodeID == that.targetNodeID ); }

      return false;
      }

      @Override
      public int hashCode()

      { return new Long( sourceNodeID ).hashCode() + new Long( targetNodeID ).hashCode(); }

      }
      [/CODE]

      No I want to have roo managed entity Edge that looks like the following now

      [CODE]
      @Entity
      @Table( name = "EDGE" )
      public class Edge implements Serializable {
      private static final long serialVersionUID = 6090794895049089364L;

      @Column( name = "EDGETYPE" )
      private EdgeType edgeType;

      public EdgeType getEdgeType()

      { return edgeType; }

      public void setEdgeType( EdgeType edgeType )

      { this.edgeType = edgeType; }

      @EmbeddedId
      private EdgeId edgeId;

      public EdgeId getId()

      { return edgeId; }

      public void setId( EdgeId id )

      { this.edgeId = id; }

      public EdgeId getEdgeId()

      { return edgeId; }

      public void setEdgeId( EdgeId id )

      { this.edgeId = id; }

      }
      [/CODE]

      I want it in the following way

      [CODE]
      @RooEntity(identifierType = EdgeId.class, embeddedIdentifier = true)
      @Entity
      @Table( name = "EDGE" )
      public class Edge implements Serializable {
      private static final long serialVersionUID = 6090794895049089364L;

      @Column( name = "EDGETYPE" )
      private EdgeType edgeType;
      }
      [CODE]

      In the @RooEntity - it is great to have something called embeddedIdentifier with true and false options, false being the default option.

        Issue Links

          Activity

          Hide
          Enrique Ruiz (DiSiD) added a comment -

          Ben, Stefan, I think we could work on this, but we would need some guidance.

          Show
          Enrique Ruiz (DiSiD) added a comment - Ben, Stefan, I think we could work on this, but we would need some guidance.
          Hide
          Ben Alex added a comment -

          SVN commit 782 contains slight fixes to constructor creation of IdClass.

          Show
          Ben Alex added a comment - SVN commit 782 contains slight fixes to constructor creation of IdClass.
          Hide
          Alan Stewart added a comment -

          Basic support added for composite keys. New @RooIdentifier annotation provided. If an entity is created with a --identifierType specified with something other than a class in the JDK (ie "java...") a new class will be created annotated with @RooIdentifier, which will create an @Embeddable annotation in the identifier's ITD . The entity class will have the id class declaration annotated with @EmbeddedId. Fields can be added to the identifier's .java file and can be annotated with @Id which will cause Roo to create a constructor for all @Id-annotated fields. Accessors are also created in the ITD.

          Show
          Alan Stewart added a comment - Basic support added for composite keys. New @RooIdentifier annotation provided. If an entity is created with a --identifierType specified with something other than a class in the JDK (ie "java...") a new class will be created annotated with @RooIdentifier, which will create an @Embeddable annotation in the identifier's ITD . The entity class will have the id class declaration annotated with @EmbeddedId. Fields can be added to the identifier's .java file and can be annotated with @Id which will cause Roo to create a constructor for all @Id-annotated fields. Accessors are also created in the ITD.
          Hide
          Alan Stewart added a comment -

          To clarify, all fields declared in the identifier class's ".java" file will be used to form the composite key. The @Id annotation is ignored and is not required in the @Embeddable class. If no fields are declared in the identifier class a default id field is created in the ITD of type java.lang.Long

          Show
          Alan Stewart added a comment - To clarify, all fields declared in the identifier class's ".java" file will be used to form the composite key. The @Id annotation is ignored and is not required in the @Embeddable class. If no fields are declared in the identifier class a default id field is created in the ITD of type java.lang.Long
          Hide
          Alan Stewart added a comment -

          @RooIdentifier now specifies three new attributes: idFields, idTypes, and idColumns. These three attributes are arrays of strings. The idFields array declares what fields get created in the ITD. The size of the idFields and idTypes arrays, if specified, must be the same. Also, if idColumns is specified, then its size must also be the same as the idFields array.

          Show
          Alan Stewart added a comment - @RooIdentifier now specifies three new attributes: idFields, idTypes, and idColumns. These three attributes are arrays of strings. The idFields array declares what fields get created in the ITD. The size of the idFields and idTypes arrays, if specified, must be the same. Also, if idColumns is specified, then its size must also be the same as the idFields array.
          Hide
          Alan Stewart added a comment -

          @RooIdentifier now requires no attributes. Primary key fields are now introduced in the .java file or added automatically into the ITD during the database reverse engineering process.

          Show
          Alan Stewart added a comment - @RooIdentifier now requires no attributes. Primary key fields are now introduced in the .java file or added automatically into the ITD during the database reverse engineering process.
          Hide
          Alan Stewart added a comment -

          More enhancements in Git ID c8b88b42c0afe021edf1453d3d9e88658c7e5d1d.

          Show
          Alan Stewart added a comment - More enhancements in Git ID c8b88b42c0afe021edf1453d3d9e88658c7e5d1d.

            People

            • Assignee:
              Alan Stewart
              Reporter:
              Chiradip Mandal
            • Votes:
              15 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: