5

I'm trying to migrate my Thorntail application from java 8 to java 11 and I am having problems with entity's relationships. The used mapping works fine with java 8 but in java 11 i have this error:

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].

My Entity mapping is like this:

@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
}

I tried to remove the child reference to the parent but then the EntityManager won't find any defined NamedQuery. Other thing I tried was to switch to hibernate and this mappings works but had some problems persisting the entities.

I am using Thorntail v2.4.0.Final and Eclipselink v2.7.3.

Does anyone have any clue of what might be the problem?

I created a similar hierarchy in a small project and uploaded it to github if anyone wants to take a closer look -> githubProject.

4

1 回答 1

2

这是一个奇怪的例外。我不知道它是否会修复它,但是您的@OneToMany映射应该使用mappedBy属性而不是指定@JoinColumns. 例如Table3.table2应该像这样映射:

    @OneToMany(mappedBy="table2", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private List<Table3> table3List;
于 2019-07-03T23:45:24.793 回答