0

私はこの例外を持っています!! ここに私のモデルクラスがあります

@Entity
public class User extends Model {

    @OneToMany(mappedBy="email", cascade=CascadeType.ALL)
    public List<Photo> photo;

    @Email
    @Required
    @Unique
    public String email;

    @Required
    public String passwordHash;

    @Required
    public String education;

    @Required
    public String fname;

    @Required
    public String lname;

    @Required
    public Date dob;

    @Required
    public String gender;

    @Required
    public String country;

    @Required
    public Long phone;

    @Required
    public String status;

    @Required
    public String jobtitle;

    @Required
    public String company;

    @Required
    public String industry;

    @Required
    public Date addDate;

    public String needConfirmation;

public User(String email, String password, String fname,
                String lname, Date dob, String gender, String country,
                Long phone, String status, String education, String jobtitle, String company, String industry) {
        //all initialization here
    }
}

どこが間違っているのか教えてください playframework× 2289


this is my photo class, and please tell me how can I allow JPA to generate my database


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package models;

import controllers.Users;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import play.db.jpa.Model;

/**
 *
 * @author nPandey
 */
@Entity
public class Photo extends Model{

    public String photoname;

    @ManyToOne
    public User email;

    public String owner;

    public Photo(){

    }

    public Photo(User email, String photo){
        this.photoname=photo;
        this.email=email;
        this.owner=email.email;
    }

}
4

4 に答える 4

0

以下のようにコードを編集してみてください - ユーザーモデルで

    @OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
    public List<Photo> photos;

写真モデル

    @ManyToOne
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "email", nullable = false, insertable = false, updatable = false)
    public User user;

これを参照して確認してください - http://en.wikibooks.org/wiki/Java_Persistence/OneToMany#Example_of_a_OneToMany_relationship_and_inverse_ManyToOne_annotations

于 2013-11-18T11:21:08.247 に答える
0

エンティティが永続化/更新されているときに、必須フィールドが欠落していないことを確認してください。また、DB のユーザー テーブルにどのような制約が設定されているかを確認します (一意のキー、外部キー、null 以外など)。

于 2012-05-20T06:08:45.370 に答える
0

Your mappedBy value makes little sense. It is used on the passive end of a bi-directional association. In those cases it points to the attribute on the other class on the other side of the relationship. You are pointing it to one of the attributes of the User class. Perhaps your Photo class has a email attribute, but is that of type User ( i am guessing not). So if this is a bi-directional association, set the mappedBy value to the attribute on Photo having the corresponding @ManyToOne "back" to the User. If it is a unidirectional association, remove the mappedBy and perhaps use @JoinColumn to use the foreign key mapping strategy of unidirectional one-to-many

于 2012-05-20T06:42:33.060 に答える