【发布时间】:2012-12-25 13:09:08
【问题描述】:
我刚刚开始使用 Play Framework。完成教程(涵盖基本功能)后,我尝试在数据库和游戏之间建立连接。我的一个关系有架构:
CREATE TABLE IF NOT EXISTS `shop`.`CatPath` (
`parentC` INT NOT NULL ,
`childC` INT NOT NULL ,
`depth` INT NOT NULL ,
PRIMARY KEY (`parentC`, `childC`)
)
所以我建立了模型的类:
@Entity
public class CatPath extends Model {
@EmbeddedId
public CatPathKey key;
public Long depth;
public class CatPathKey {
public Long parentC;
public Long childC;
}
public static Finder<CatPathKey, CatPath> find = new Finder<CatPathKey, CatPath>(CatPathKey.class, CatPath.class);
编译后出现异常:
PersistenceException: Could not find BeanDescriptor for class models.CatPath$KatPathKey. Perhaps the EmbeddedId class is not registered?
我不知道问题出在哪里,当我按照教程进行时,一切正常。我的代码和教程的唯一区别是关键:我有复合键,在教程中只有一列是关键。为什么在教程中不需要“注册课程”?我想,它是自动注册的,但为什么现在用复合键,它不是?
我试着找了一些资料,我找到了:http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Entities/Ids/EmbeddedId 这个 xml 代码是“类注册”吗?在 Play 框架教程和详细主题中没有提到 xml,我没有对模型的类做任何事情,一切正常。
【问题讨论】: