我正在使用 Seam 框架。我有 2 个实体:
请求.java
@Entity
@Table(name = "SRV_REQUEST")
public class Request {
private Long id;
@Id
@Column(name = "ID_")
public Long getId() {
return id;
}
和RequestEvent.java
@Entity
@Table(name = "SRV_REQUEST_EVENT")
public class RequestEvent {
private Long id;
private Request request;
@Id
@GeneratedValue
@Column(name = "ID_")
public Long getId() {
return id;
}
@ManyToOne
public Request getRequest() {
return request;
}
当我进行此交易时:
Request request = new Request();
// I have to set ID manually
request.setId(12345);
entityManager.persist(request);
RequestEvent event = new RequestEvent();
event.setRequest(request);
entityManager.persist(event);
我收到了这个错误:
object references an unsaved transient instance - save the transient instance before flushing: kz.gov.mci.ipsc.services.RequestEvent.request -> kz.gov.mci.ipsc.services.Request