I'm trying to create a little project around EJB / JPA linked to a Mysql database. I got two tables FctData and RefKpiDataQuery linked by a foreign key.
我正在尝试围绕连接到Mysql数据库的EJB / JPA创建一个小项目。我有一个由外键链接的两个表FctData和RefKpiDataQuery。
FctData :
public class FctData implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "DATA_ID")
private Long dataId;
...
@JoinColumn(name = "DATA_QUERY_REF", referencedColumnName = "KPI_DATA_QUERY_ID")
@ManyToOne(cascade = CascadeType.ALL)
private RefKpiDataQuery dataQueryRef;
RefKpiDataQuery :
public class RefKpiDataQuery implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "KPI_DATA_QUERY_ID")
private Long kpiDataQueryId;
...
@OneToMany(cascade = CascadeType.ALL, mappedBy = "dataQueryRef")
private Set<FctData> fctDataSet;
I got a client which is just trying to insert a FctData in the database
我有一个客户端,它只是试图在数据库中插入一个FctData
RefKpiDataQuery refKpiDataQuery = new RefKpiDataQuery();
refKpiDataQuery.setKpiDataQueryId((long) 2);
FctData fctData = new FctData();
fctData.setDataQueryRef(refKpiDataQuery);
fctDataFacade.insert(fctData);
The Facade is a kind of DAO. This thing is working great with object which don't have a FK.
Facade是一种DAO。对于没有FK的对象,这个东西很好用。
Here is the error that i get in my log :
这是我在日志中收到的错误:
Field 'DATA_QUERY_REF' doesn't have a default value {prepstmnt 7235700 INSERT INTO FCT_DATA(DATA_DATE, DATA_TIME, DATA_VALIDITY, DATA_VALUE, ISACTIVE, UPDATE_OWNER, UPDATE_TS) VALUES (?, ?, ?, ?, ?, ?, ?)
As we can see in my insert it never talks about the dataQuery. Someone can explain me what did i miss ? I can't find my mistake.
正如我们在插入中看到的,它从不谈论dataQuery。有人可以解释一下我错过了什么?我找不到我的错误。
Thanks for your time. Cheers
谢谢你的时间。干杯
1 个解决方案
#1
0
I finally got it work by deleting all the
我终于通过删除所有的工作得到了它
@Basic(optional = false)
Also there is no need to add the cascade = CascadeType.ALL
此外,无需添加cascade = CascadeType.ALL
#1
0
I finally got it work by deleting all the
我终于通过删除所有的工作得到了它
@Basic(optional = false)
Also there is no need to add the cascade = CascadeType.ALL
此外,无需添加cascade = CascadeType.ALL