2011-12-19 3 views
2

재생 프레임 워크 응용 프로그램에서 OneToOne 매핑을 성공적으로 구현하는 데 어려움을 겪고 있습니다. 내가이OneToOne 매핑 - Play Framework Enitity

예는 다음과 같습니다

@Entity 
    public class Profile extends GenericModel { 
    @Id 
    @GeneratedValue(generator = "foreignGenerator") 
    @GenericGenerator(name = "foreignGenerator", strategy = "foreign", 
      parameters = @Parameter(name = "property", value = "user")) 
    public static int id; 

    @OneToOne(mappedBy="profile", cascade = {CascadeType.ALL}) 
    public static User user; 
} 

과 :

@Entity 
    public class User extends Model { 

    @Required 
    public String firstName; 

    @Required 
    public String surname; 
} 

가 발생이 설정에서 :

org.hibernate.AnnotationException: No identifier specified for entity: models.Profile 

사람이에 대한 몇 가지 빛을 던질 수 있습니까?

편집가 : Christian Boariu's answer 당, 나는 당신이 제안 및 사용자에 무슨에 프로필을 수정 한 :

@Entity 
    public class User extends GenericModel { 

@Id 
@GeneratedValue(strategy = GenerationType.AUTO) 
public Long user_id; 

@Required 
public String firstName; 

@Required 
public String surname; 

@OneToOne(cascade = {CascadeType.ALL}) 
@PrimaryKeyJoinColumn(name = "user_id", referencedColumnName = "profile_id") 
public Profile profile; 

public Profile getProfile() { 
    return profile; 
} 

public void setProfile(Profile profile) { 
    this.profile = profile; 
} 
} 

는 또한 게터를 추가/세터 프로필 :

public User getUser() { 
    return user; 
} 

public void setUser(User user) { 
    this.user = user; 
} 

을하지만, 내가 지금 hibernate.id.IdentifierGenerationException: null id generated for:class models.Profile을 얻는 것. 정정하는 방법을 모르십니까?

감사

+0

또한 모델에서 클래스를 모두 확장하는 것이 좋습니다.이 경우 모델 수퍼 클래스가이 작업을 수행하기 때문에 더 이상 id 필드를 선언 할 필요가 없습니다. –

답변

1

이 문제는 아이디 정의에 관한 것입니다.

static이어야합니다.

또한 사용자는 정적이어서는 안됩니다.

UPDATE :

그래서 클래스는 다음과 같이해야한다 :

@Entity 
    public class Profile extends GenericModel { 
    @Id 
    @GeneratedValue(generator = "foreignGenerator") 
    @GenericGenerator(name = "foreignGenerator", strategy = "foreign", 
      parameters = @Parameter(name = "property", value = "user")) 
    public int id; 

    @OneToOne(mappedBy="profile", cascade = {CascadeType.ALL}) 
    public User user; 
} 
+0

프로파일의 fab yes id는 정적이어서는 안됩니다. 또한 사용자가 정적이되어서는 안된다고 말할 때 무슨 뜻입니까? – Chahal

+0

의미 : 사용자 필드에서 정적 키워드를 제거합니다. – wassertim

0

가 수정되었습니다. 위와 같이 @OneToOne 문제와 hibernate.id.IdentifierGenerationException : null id 생성 : class models.Profile은 null id를 가진 엔티티를 유지하려고했기 때문입니다. @primaryKeyJoin을 사용하므로 @JoinColumn으로 변경되었습니다.