我刚刚开始使用 Play 框架。完成教程(涵盖基本功能)后,我尝试在数据库和游戏之间设置连接。我的一个关系有模式:
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 http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Entities/Ids/EmbeddedId这个xml代码是“类注册”?在 Play 框架教程和详细主题 xml 中没有提到,我没有对模型的类执行任何操作,一切正常。