【问题标题】:Exception thrown with OneToMany annotationOneToMany 注释引发的异常
【发布时间】:2012-07-23 10:55:16
【问题描述】:

在我使用 EBean ORM 的 Play 2.0 应用程序中,我有以下类:

@Entity
public class User extends Model {

    @Id
    public Long id;

    @Constraints.Required
    public String someString;

    @OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
    @OrderBy("index")
    public List<UserImage> userImages = new ArrayList<UserImage>();
}

除非我完全注释掉 @OneToMany 行,否则应用程序会抛出 RunTimeException 声明

读取 models.User 的注释时出错

我在这里提到的UserImage 类看起来像这样:

public class UserImage extends Model {
    @Id
    public long id;

    @Constraints.Min(0)
    public int index;

    @Column(name="user_id")
    @ManyToOne
    public User user;

    //...
}

我在这里做错了什么?为什么 EBean 不理解我的注解?

【问题讨论】:

  • 您是否在 UserImage 类上设置了@Entity 注释(示例代码中未显示)?
  • 不,不,我没有。这就是解决方案。啊。谢谢。

标签: jpa playframework ebean


【解决方案1】:

我认为您错过了UserImage class 上的@Entity 注释:

@Entity
public class UserImage extends Model {
    @Id
    public long id;

    @Constraints.Min(0)
    public int index;

    @Column(name="user_id")
    @ManyToOne
    public User user;

    //...
}

【讨论】:

    猜你喜欢
    • 2014-01-03
    • 1970-01-01
    • 2015-12-25
    • 1970-01-01
    • 1970-01-01
    • 2016-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多