ebean和play框架中的复合键 [英] compound key in ebean and play framework

查看:90
本文介绍了ebean和play框架中的复合键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用Play Framework.在完成教程(了解基本功能)之后,我尝试建立数据库与播放之间的连接.我的关系之一是架构:

I've just started using Play Framework. After I finished tutorials (covering basic functions) I try setup connection between database and play. One of my relations has schema:

CREATE  TABLE IF NOT EXISTS `shop`.`CatPath` (
  `parentC` INT NOT NULL ,
  `childC` INT NOT NULL ,
  `depth` INT NOT NULL ,
  PRIMARY KEY (`parentC`, `childC`) 
  )

所以我建立了模型的类:

so I built model's class:

@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?

我不知道问题出在哪里,当我按照教程学习时,一切正常.我的代码和教程的唯一区别是密钥:我有复合密钥,在教程中只有一列是密钥.为什么在教程中不需要注册课程"?我猜它是自动注册的,但是为什么现在没有复合键呢?

I don't know where is a problem, when I followed tutorials everything worked. Only difference between my code and tutorial's is key: I have compound key, in tutorials only one column makes key. Why in tutorials 'registering class' wasn't necessary? I guess, it was registered automatically but why now, with compound key, it isn't?

我试图找到一些信息,发现: http: //wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Entities/Ids/EmbeddedId 此xml代码是类注册"?在Play框架教程和详细主题中都没有提到xml,我对模型的类没有做任何事情,并且一切正常.

I tried to find some information, I found: http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Entities/Ids/EmbeddedId this xml code is 'class registering'? In Play framework tutorials and detailed topics xml isn't mentioned, I didn't do anything with my model's classes and everything worked.

推荐答案

您必须在CatPathKey类下添加@Embeddable批注:

You have to add the @Embeddable annotation under your CatPathKey class:

@Embeddable
public class CatPathKey {

        public Long parentC;
        public Long childC;
} 

这篇关于ebean和play框架中的复合键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆