public class Maintenance implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
private Long id;
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "maintenance_issue_mod",
joinColumns = @JoinColumn(name = "maintenance_id"),
inverseJoinColumns = @JoinColumn(name = "issue_mod_id"))
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<IssueMod> issueMod = new HashSet<>();
@OneToOne(fetch = FetchType.LAZY, targetEntity = COrder.class)
@NotNull
@NotFound(
action = NotFoundAction.IGNORE)
@JoinColumn(name="c_order_id", nullable = false, insertable = false,
updatable = false)
private COrder cOrder;
@OneToOne
@JoinColumn(name = "invoice_id")
private Invoice invoice;
@OneToOne
@JoinColumn(name = "referred_invoice_id")
private Invoice referredInvoice;
getter and setter
这是Maintenance类,Maintenance和COrder的关系是OneToOne。
这是更高级的课程
public class COrder implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
private Long id;
@CreatedDate
@NotNull
@Column(name = "created", nullable = false)
private Instant created = Instant.now();
@Size(max = 255)
@NotNull
@Column(name = "order_number", length = 255, nullable = false, unique = true)
private String orderNumber;
Maintenance maintenance = maintenanceRepository.findById(maintenanceInvoiceDTO.getMaintenanceId());
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> " +maintenance);
COrder currentOrder = cOrderRepository.findOneById(maintenance.getcOrder().getId());
在服务中通过maintenanceId查找维护 那么我们得到以下错误 '无法在ID为1的in.bsrnetwork.ctrack.domain.COrder中找到' 但cord id 1存在于corder表中