Java实体管理器合并不编辑只创建新记录
嗨,我不能让合并工作它只生成新记录,但不更新记录 编辑: 对象:Java实体管理器合并不编辑只创建新记录,java,merge,entitymanager,Java,Merge,Entitymanager,嗨,我不能让合并工作它只生成新记录,但不更新记录 编辑: 对象: @Entity(name = "ALLEGRO_TRANSACTION") public class AllegroTransactionImpl implements AllegroTransaction{ @Id @Column(name = "ID") @GeneratedValue(strategy = GenerationType.AUTO) protected Long id;
@Entity(name = "ALLEGRO_TRANSACTION")
public class AllegroTransactionImpl implements AllegroTransaction{
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.AUTO)
protected Long id;
@Column(name = "ALIEXPRESS_NUMBER")
protected String aliexpressNumber;
@Column(name = "CREATE_DATE")
protected Date createDate;
@OneToOne(optional = true, targetEntity = PaymentTypeImpl.class)
@JoinColumn(name = "PAYMENT_ID")
protected PaymentTypeImpl paymentType;
@Column(name = "FIRST_NAME")
protected String firstName;
@Column(name = "LAST_NAME")
protected String lastName;
@Column(name = "PRICE")
protected float price;
@Column(name = "EMAIL")
protected String email;
@Column(name = "PHONE", nullable = true)
protected String phone;
@Column(name = "ADDRESS", columnDefinition="LONGTEXT")
protected String address;
@Column(name = "ATTENTION", columnDefinition="LONGTEXT")
protected String attention;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getAliexpressNumber() {
return aliexpressNumber;
}
public void setAliexpressNumber(String aliexpressNumber){
this.aliexpressNumber = aliexpressNumber;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public PaymentTypeImpl getPaymentType() {
return paymentType;
}
public void setPaymentType(PaymentTypeImpl paymentType) {
this.paymentType = paymentType;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getAttention() {
return attention;
}
public void setAttention(String attention) {
this.attention = attention;
}
}
经理:
@Service
public class AllegroTransactionService {
private final static Logger logger = Logger.getLogger(AllegroTransactionService.class);
@PersistenceContext( unitName = "allegroTransactionPersistenceUnit", type= PersistenceContextType.EXTENDED )
protected EntityManager em;
public List<AllegroTransactionImpl> readAllegroTransactionByCreateDate()
{
Query query = this.em.createQuery( "SELECT allegroTransaction FROM com.springapp.mvc.classes.AllegroTransactionImpl allegroTransaction ORDER BY createDate DESC" );
return query.getResultList();
}
@Transactional
public AllegroTransactionImpl saveAllegroTransaction(AllegroTransactionImpl allegroTransaction)
{
this.em.merge( allegroTransaction );
return allegroTransaction;
}
}
还是不能让它工作。。。也许你们能想出办法?实体管理器工作我可以很容易地让ReadAllegorTransaction函数工作,但合并不工作-它创建另一个对象问题没有正确通过ID参数你应该考虑解释和提供更多的信息…您的模式是什么样子的?您的对象是如何定义的?等等…在你的评论之后更新了帖子你作为参数传递的对象有有效的id吗?我很笨,非常感谢你