播放框架2 ebean @manytoone列指定两次 [英] play framework 2 ebean @manytoone Column specified twice

查看:128
本文介绍了播放框架2 ebean @manytoone列指定两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一些关于ebean的问题(使用Play Framework 2版本2.2.1) 我有两节课:

I'm running to some problems with ebean (using play framework 2 version 2.2.1) I have two classes:

我的图类:

public class Graph extends Model {
     @Id
     @Column(name="id")
     private String id;

     @Column(name="type")
     private String type;

     @OneToMany(mappedBy="valGraph", cascade=CascadeType.ALL)
     private List<Val> valItems; 

和我的值类(带有Val.graphId外键Graph.id):

and my value class (with Val.graphId foreign key Graph.id):

public class Val extends Model
     @Id
     @Column(name="valId")
     private String valId;  

     @Id
     @Column(name="graphId")
     private String graphId;

     @Column(name="Key")
     private String Key;

     @Column(name="Value")
     private String Value;

     @ManyToOne(fetch = FetchType.LAZY)
     @JoinColumn(name="graphId")
     private Graph valGraph;

但是当尝试保存新项目时,出现此错误:

but when trying to save a new item i get this error:

javax.persistence.PersistenceException:执行DML bindLog []错误[错误两次指定列'graphId'"

javax.persistence.PersistenceException: ERROR executing DML bindLog[] error[Column 'graphId' specified twice]

推荐答案

在网络上搜索了无数人之后,我找到了这个答案

After numerous searchers around the web I found this answer here - thanks to jtal!

仅对问题进行总结:

使用Ebean,我创建了一个@ManyToOne实体,该实体无论如何都不会在数据库中实现, 在我的情况下,甚至更多的加入字段

Using Ebean i have made a @ManyToOne entity that is not implemented in the database in anyway, even more the join field, in my case

graphId

graphId

是一个有效的字段,具有自己的值.

is a valid field that has values of its own.

当尝试在该字段上连接该列时,它总是会失败,因为它会创建以下sql查询:

when trying to join the column on that field, it will always fail because it creates this sql query:

SELECT 
*
FROM
    Val;

select 
    t0.valId c0, 
    t0.graphId c1, 
    t0.Key c2, 
    t0.Value c3, 
    t0.graphId c4 <---- notice this duplicate
from 
    graph_val t0 

为了解决这个问题,我告诉ebean 不要使用第二组属性.

in order to solve this, i tell ebean not to use the second set of properties.

我的新ebean元素如下所示:

my new ebean element looks like this:

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="graphId", insertable = false, updatable = false)
private Graph valGraph;

它有效! =)

这篇关于播放框架2 ebean @manytoone列指定两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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