【问题标题】:Eclipselink gives validation exceptionEclipselink 给出验证异常
【发布时间】:2015-04-24 17:26:04
【问题描述】:

我使用 MySQLWorkbench 作为建模工具来创建我的数据库。我生成了一个简单的 testDB,用于测试 JPA/Eclipselink、Netbeans 实体和 Web 服务生成器。当我生成实体和服务时,我收到如下错误消息:

Exception Description: [class com.rako.rma.Rma] uses a non-entity [class com.rako.rma.Product] as target entity in the relationship attribute [field productserialNumberLOTN].
at org.eclipse.persistence.exceptions.ValidationException.nonEntityTargetInRelationship(ValidationException.java:1378)

RMA 实体

public class Rma implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "rma_id")
private Integer rmaId;
@Size(max = 45)
@Column(name = "temp1")
private String temp1;
@JoinColumn(name = "product_serialNumber_LOTN", referencedColumnName = "serialNumber_LOTN")
@ManyToOne(optional = false)
private Product productserialNumberLOTN;

产品实体

public class Product implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 20)
@Column(name = "serialNumber_LOTN")
private String serialNumberLOTN;
@Size(max = 45)
@Column(name = "temp1")
private String temp1;
@Size(max = 45)
@Column(name = "temp2")
private String temp2;
@JoinColumn(name = "serialNumber_LOTN", referencedColumnName = "LOTN", insertable = false, updatable = false)
@OneToOne(optional = false)
private SerialNumber serialNumber;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "productserialNumberLOTN")
private Collection<Rma> rmaCollection;

序列号实体

public class SerialNumber implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 20)
@Column(name = "LOTN")
private String lotn;
@Size(max = 45)
@Column(name = "temp")
private String temp;
@OneToOne(cascade = CascadeType.ALL, mappedBy = "serialNumber")
private Product product;

问题

1) 我的数据库设计是否错误?

2) Netbeans JPA 生成器是否正常工作?

3) 如果它不能 100% 工作,我该如何修复我的 jpa 表示法以使这种关系正常工作?

【问题讨论】:

  • 当我粘贴到 netbeans 项目时,实体看起来很好。你的 persistence.xml 是什么样的?服务器可以在之后启动,还是只是在产生问题时启动?
  • 当生成和服务器不启动时。 Netbeans 8.02 和 Glassfish 4.1。
  • 我认为,作为 pk 的字符是问题所在。如果我将一个字段 serialNumberID 添加为 pk​​ 并且它只是自动递增 int,则一切正常。问题是 REST 服务在 Netbeans(测试休息)中也不起作用,即使服务器已启动并正在运行,但使用 serialNumberID 他们正在工作......
  • 您显示的内容似乎没有问题,因此问题可能是您的类路径上有多个类实例,因此选择了其他版本的产品向上。检查它是如何被打包和部署的
  • 检查Product是否有任何lamdba表达式。有一个bug

标签: hibernate jpa eclipselink mysql-workbench netbeans-8


【解决方案1】:

您的每个实体类都需要在它们之上添加@Entity 注释:

@Entity
public class Product implements Serializable {
...

【讨论】:

  • 我收到了,但这不是我的原因。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-09
  • 1970-01-01
  • 1970-01-01
  • 2017-03-17
  • 2016-05-05
  • 1970-01-01
相关资源
最近更新 更多