[英]JPA Hibernate Clildren with @EmbeddedId not loadded on Weblogic server but loadded in integration test
I have a problem with JPA and Hibernate where I have 2 entities that are in relation of 1 to many.我有 JPA 和 Hibernate 的问题,我有 2 个实体,它们是一对多的关系。 On local host on the integraiton test using H2 the things are as they should (children are loaded), when deployed into the weblogic server that is using Oracle as DB, the children are not loaded.
在使用 H2 进行集成测试的本地主机上,一切正常(加载子项),当部署到使用 Oracle 作为 DB 的 weblogic 服务器时,子项未加载。 Any idea on this?
对此有什么想法吗? The entities definitions are:
实体定义是:
@Entity
@Table(name = "TB_MASTER")
@Data
@ToString
@NoArgsConstructor
public class Case implements Serializable {
private static final long serialVersionUID = 1919288768119684307463L;
@Id
@Column(name = "ID", nullable = false, length = 55)
private String id;
@Column(name = "CODE_ADR", nullable = false, length = 100)
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true, mappedBy = "id.masterId")
@EqualsAndHashCode.Exclude
private Set<MasterReference> references = new TreeSet<>();
}
The EmbeddedId class: EmbeddedId class:
@Data
@AllArgsConstructor
@EqualsAndHashCode
@NoArgsConstructor
@Embeddable
public class MasterReferenceId implements Serializable, Comparable {
@ManyToOne(optional = false)
@JoinColumn(name = "MASTER_ID", nullable = false)
@ToString.Exclude
@EqualsAndHashCode.Exclude
private Master masterId;
@Column(name = "REF", nullable = false, length = 42)
private String reference;
@Column(name = "SHORCUT", nullable = false, length = 100)
private String shortcut;
@Column(name = "REF_DATE")
private Date refDate;
@Column(name = "REF_BACK", length = 1)
@Convert(converter = BooleanToNumberConverter.class)
private Boolean refBack;
@Column(name = "REF_DATA_ROW", length = 2000)
private String refDataRow;
@Override
public int compareTo(Object o) {
if (o instanceof MasterReferenceId && ((MasterReferenceId) o).getReference() != null && ((MasterReferenceId) o).getReference() != null) {
return ((MasterReferenceId) o).getReference().compareTo(this.getReference());
}
return 0;
}
}
The cild entity:子实体:
@Entity
@Table(name = "TB_MASTER_REFERENCE")
@Data
@ToString
@NoArgsConstructor
public class MasterReference implements Serializable, Comparable {
private static final long serialVersionUID = -517596820344348395356L;
@EmbeddedId
private MasterReferenceId id;
@Column(name = "UPDATE_DATE", nullable = false)
private Date updateDate;
@Column(name = "COMMENTS", length = 4000)
private String comments;
@Override
public int compareTo(Object o) {
if (o instanceof MasterReference && ((MasterReference) o).getId() != null) {
return ((MasterReference) o).getId().compareTo(this.getId());
}
return 0;
}
}
Try this instead:试试这个:
public class MasterReference implements Serializable, Comparable {
@EmbeddedId
private MasterReferenceId id;
@ManyToOne(optional = false)
@JoinColumn(name = "MASTER_ID", nullable = false)
@MapsId("masterId")
private Master masterId;
..
}
public class MasterReferenceId implements Serializable, Comparable {
private String masterId;
..
}
Change the mappedBy in the OneToMany on references to just "masterId" so that it uses the reference mapping instead of trying to use the embeddedId.将引用上的 OneToMany 中的 mappedBy 更改为仅“masterId”,以便它使用引用映射而不是尝试使用 embeddedId。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.