Mặc dù tất cả các bài đăng khác, tôi không thể tìm thấy giải pháp cho lỗi này với GlassFish, trên MacOSX, NetBeans 7.2.Cột lặp lại khác trong ánh xạ cho lỗi thực thể
Here the error :
SEVERE: Exception while invoking class org.glassfish.persistence.jpa.JPADeployer
prepare method
SEVERE: Exception while preparing the app
SEVERE: [PersistenceUnit: supmarket] Unable to build EntityManagerFactory
...
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity:
com.supmarket.entity.Sale column: customerId
(should be mapped with insert="false" update="false")
Đây mã:
Sale.java
@Entity
public class Sale {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(nullable=false)
private Long idFromAgency;
private float amountSold;
private String agency;
@Temporal(javax.persistence.TemporalType.DATE)
private Date createdate;
@Column(nullable=false)
private Long productId;
@Column(nullable=false)
private Long customerId;
@ManyToOne(optional=false)
@JoinColumn(name="productId",referencedColumnName="id_product")
private Product product;
@ManyToOne(optional=false)
@JoinColumn(name="customerId",referencedColumnName="id_customer")
private Customer customer;
public void Sale(){}
public void Sale(Long idFromAgency, float amountSold, String agency
, Date createDate, Long productId, Long customerId){
...
}
// then getters/setters
}
Customer.java
@Entity
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="id_customer")
private Long id_customer;
@Column(nullable=false)
private Long idFromAgency;
private String gender,
maritalState,
firstname,
lastname,
incomeLevel;
@OneToMany(mappedBy="customer",targetEntity=Sale.class, fetch=FetchType.EAGER)
private Collection sales;
public void Customer(){}
public void Customer(Long idFromAgency, String gender, String maritalState,
String firstname, String lastname, String incomeLevel) {
...
}
}
Product.java
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="id_product")
private Long id_product;
@Column(nullable=false)
private Long idFromAgency;
private String name;
@OneToMany(mappedBy="product",targetEntity=Sale.class, fetch=FetchType.EAGER)
private Collection sales;
//constructors + getters +setters
}
tôi nhận được lỗi tương tự, nhưng tình hình của tôi là một chút khác nhau. Thực thể của tôi có thể là cha của một hoặc nhiều thực thể cùng loại. Những đứa trẻ có một tham chiếu về id của cha của họ cũng như một id duy nhất của riêng mình. Làm thế nào tôi có thể giải quyết một phụ thuộc vòng tròn như vậy? – Serban
@Serban Đặt câu hỏi của riêng bạn bằng mã. –
@JBNizet Làm thế nào sau đó tôi có thể * lưu * một Bán với một số 'customerId' cụ thể? (ví dụ: từ JSON). –