我正在尝试将Thorntail应用程序从Java 8迁移到Java 11,但是实体之间的关系存在问题。使用的映射在Java 8上工作正常,但在Java 11中我出现此错误:
2019-07-03 15:48:12,713 ERROR [stderr] (main) Exception Description:
Predeployment of PersistenceUnit [p-unit] failed.
2019-07-03 15:48:12,713 ERROR [stderr] (main) Internal Exception:
Exception [EclipseLink-7250] (Eclipse Persistence Services -
2.7.3.v20180807-4be1041):
org.eclipse.persistence.exceptions.ValidationException
2019-07-03 15:48:12,713 ERROR [stderr] (main) Exception Description:
[class com.mytest.data.specific.entities.Table3] uses a non-entity
[class com.mytest.data.specific.entities.Table2] as target entity
in the relationship attribute [field table2].
我的实体映射如下:
@MappedSuperclass
public abstract class AbstractIdEntity extends AbstractEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
public Long getId() {
return id;
}
protected void setId(final Long id) {
this.id = id;
}
}
@Entity
@Table(name = "table_2")
public class Table2 extends AbstractIdEntity {
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "table_1_id", referencedColumnName = "id")
private Table1 table1;
@Column(name = "some_info", nullable = false)
private String someInfo;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "table_2_id")
private List<Table3> table3List;
//more stuff
}
@Entity
@Table(name = "table_3")
public class Table3 extends AbstractIdEntity {
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "table_2_id", referencedColumnName = "id")
private Table2 table2;
@Lob
@Column(name = "some_bytes", nullable = false)
private byte[] someBytes;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "table_3_id")
private List<Table4> table4List;
//more stuff
}
我试图删除对父级的子级引用,但是EntityManager
找不到任何已定义的NamedQuery
。我试图做的另一件事是切换到休眠状态,这种映射有效,但是在持久化实体时遇到了一些问题。
我正在使用Thorntail v2.4.0.Final和Eclipselink v2.7.3。
有人知道这可能是什么问题吗?
我在一个小项目中创建了类似的层次结构,如果有人想仔细看,则将其上传到github-> githubProject。
答案 0 :(得分:2)
这是一个奇怪的例外。我不知道它是否可以解决它,但是您的@OneToMany
映射应该使用mappedBy
属性,而不要指定@JoinColumn
。例如Table3.table2
应该这样映射:
@OneToMany(mappedBy="table2", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<Table3> table3List;