java - 如何在 Hibernate 中引用另一个表

标签 java hibernate orm tapestry

我有两个类:UserVideo:

@Entity    
class User{
    @Id
    int id;        
    String name;
}

@Entity
    class Video{
    @Id
    int id;        
    String url;
    User user;
}

当我使用它时,出现以下错误:

Could not determine type for: User, at table: Video

我正在通过 Tapestry 使用 Hibernate。有什么建议吗?

最佳答案

非常简单:您需要在 user 字段上添加一个 @ManyToOne 注释:

@Entity
class Video {
    @Id
    int id;

    String url;

    @ManyToOne
    User user;
}

参见 Javadoc获取更多信息。

关于java - 如何在 Hibernate 中引用另一个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12975508/

相关文章:

java - 如何去除 JFrame 边框让图像触及边缘

javafx 2 CheckBoxTableCell 在表格 View 中不起作用

java - 字段中的列 ' ' 不明确

java - 通过 child build 者

php - 学说 2 延迟加载失败

node.js - 使用事务时的 Sequelize 回调

java - 从 5.2 升级到 Hibernate 5.3 后,Ear 部署因空模块而失败,我正在使用 wweblogic 12c 12.1.3

java - 在 hibernate 中使用参数进行日期转换

mysql - 在 Play 框架中持久保存 JPA 实体的最佳方式

c# - 将 Dapper 与 Oracle 用户定义类型结合使用