我试图保存一个对象,但我得到these错误:
java.lang.IllegalStateException: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing : com.example.magra.erp.models.entity.ventas.OrdenVenta.contacto -> com.example.magra.erp.models.entity.maestro.ClienteContacto
java.lang.IllegalStateException: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing : com.example.magra.erp.models.entity.ventas.OrdenVenta.cliente -> com.example.magra.erp.models.entity.maestro.Cliente
这三个实体是:
奥登文塔酒店
@Entity
@Table(name="ven_orden_venta")
public class OrdenVenta implements Serializable {
...
@ManyToOne(fetch = FetchType.LAZY)
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler, contactos"}, allowSetters = false)
private Cliente cliente;
@ManyToOne(fetch = FetchType.LAZY)
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler"}, allowSetters = false)
private ClienteContacto contacto;
...
//getters and setters
}
客户端
@Entity
@Table(name="mae_cliente")
public class Cliente implements Serializable {
...
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "cliente_id")
private List<ClienteContacto> contactos;
...
//getters and setters
}
客户联系方式
@Entity
@Table(name="mae_cliente_contacto")
public class ClienteContacto implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(length=200)
private String nombres;
@Column(length=150)
private String apellidoPaterno;
@Column(length=150)
private String apellidoMaterno;
@Column(length=15)
private String telefono;
@Column(length=15)
private String celular;
@Column(length=250)
private String correo;
private Integer idUsuarioCrea;
@Temporal(TemporalType.TIMESTAMP)
private Date fechaCrea;
private Integer idUsuarioModifica;
@Temporal(TemporalType.TIMESTAMP)
private Date fechaModifica;
//getters and setters
}
我不知道我错在哪里。先谢谢你。
搜索一个解决方案,我发现使用CascadeType.ALL解决了这个错误。但这不是我的情况。
我使用了CascadeType.ALL并删除了该表以再次创建它,但这并没有解决错误。
1条答案
按热度按时间2vuwiymt1#
首先将Cliente和ClienteContacta保存到实体中,并将创建的对象分配给OrdenVenta对象,解决了问题