gpt4 book ai didi

playframework-2.0 - ebean 和 play 框架中的复合键

转载 作者:行者123 更新时间:2023-12-04 23:58:18 25 4
gpt4 key购买 nike

我刚刚开始使用 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?

我不知道问题出在哪里,当我按照教程进行操作时,一切正常。我的代码和教程的唯一区别是关键:我有复合键,在教程中只有一列是关键。为什么在教程中不需要“注册类(class)”?我想,它是自动注册的,但为什么现在使用复合键,它不是?

我试着找了一些资料,发现: http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Entities/Ids/EmbeddedId
这个 xml 代码是“类注册”?在 Play 框架教程和详细主题 xml 中没有提到,我没有对模型的类做任何事情,一切正常。

最佳答案

您必须添加 @Embeddable您的下注 CatPathKey类(class):

@Embeddable
public class CatPathKey {

public Long parentC;
public Long childC;
}

关于playframework-2.0 - ebean 和 play 框架中的复合键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14030937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com