Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Composite foreign keys as primary key jpa

 // parent entity has simple primary key

    @Entity
    public class Employee {
       @Id long empId;
       String name;
       ...
    }

    // dependent entity uses EmbeddedId for composite key

    @Embeddable
    public class DependentId {
       String name;
       long empid;   // corresponds to primary key type of Employee
    }

    @Entity
    public class Dependent {
       @EmbeddedId DependentId id;
        ...
       @MapsId("empid")  //  maps the empid attribute of embedded id
       @ManyToOne Employee emp;
    }
Source by docs.jboss.org #
 
PREVIOUS NEXT
Tagged: #Composite #foreign #keys #primary #key #jpa
ADD COMMENT
Topic
Name
8+5 =