问题
I'm running to some problems with ebean (using play framework 2 version 2.2.1) I have two classes:
my graph class:
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;
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: ERROR executing DML bindLog[] error[Column 'graphId' specified twice]
回答1:
After numerous searchers around the web I found this answer here - thanks to jtal!
Just to summaries the problem:
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
is a valid field that has values of its own.
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
in order to solve this, i tell ebean not to use the second set of properties.
my new ebean element looks like this:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="graphId", insertable = false, updatable = false)
private Graph valGraph;
and it works! =)
来源:https://stackoverflow.com/questions/24464812/play-framework-2-ebean-manytoone-column-specified-twice