Вопрос

i try to create composite primary key in table from 2 foreign key using hibernate.but i do not now the way how to set it. @UniqueConstraint can some body help me..

Это было полезно?

Решение

you don't need @UniqueConstraint if you declare that composite key as your @EmbeddedId see this link for the example.

you only need a class to become it's composite id:

@Embeddable
public class SomeCompositeClass {
    @Column(name = "SOME_ID_1")
    private String someId1;

    @Column(name = "SOME_ID_2")
    private String someId2;

    //getter, setter methods
}

then use it inside your entity to became its @EmbeddedId :

 @Entity
 @Table(name = "YOUR_MAIN_TABLE")
 public class YourMainTable {

     @EmbeddedId
     private SomeCompositeClass myCompositeId ;

  /*setter getter methods */
 }
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top