どうかお手伝いできますか? JPAでは、OneToMany双方向リレーションシップを作成しようとしましたが、次のエラーがあります。 "[EclipseLink-63]:インスタンス作成メソッド[entity.OrderLine。]はパラメータなしで存在しないか、アクセスできません。 [EclipseLink-28019]:PersistenceUnit [simple-jpaPU]のデプロイメントが失敗しました。このPersistenceUnitのすべての工場を閉じます。JPA OneToMany双方向関係[EclipseLink-63]エラー
私の実体があります OneToManyエンティティ:
package entity;
import java.util.*;
import java.io.Serializable;
import javax.persistence.*;
import org.eclipse.persistence.annotations.TimeOfDay;
@Entity
public class Order implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Temporal(TemporalType.TIMESTAMP)
private Date creationDate;
@OneToMany(mappedBy = "o")
private List<OrderLine> orderLines;
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public List<OrderLine> getOrderLines() {
return orderLines;
}
public void setOrderLines(ArrayList<OrderLine> orderLines) {
this.orderLines = orderLines;
}
public Order(Date creationDate) {
this.creationDate = creationDate;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public String toString() {
return "entity.Order[ id=" + id + " ]";
}
}
ManyToOneエンティティ:
package entity;
import java.io.Serializable;
import javax.persistence.*;
@Entity
@Table(name="orderline_table")
public class OrderLine implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String item;
private Double unitPrice;
private Integer quantity;
@ManyToOne
Order o;
public String getItem() {
return item;
}
public void setItem(String item) {
this.item = item;
}
public Double getUnitPrice() {
return unitPrice;
}
public void setUnitPrice(Double unitPrice) {
this.unitPrice = unitPrice;
}
public Integer getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}
public OrderLine(String item, Double unitPrice, Integer quantity) {
this.item = item;
this.unitPrice = unitPrice;
this.quantity = quantity;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public String toString() {
return "entity.OrderLine[ id=" + id + " ]";
}
}
Whan::私は2つのエンティティで引数なしのコンストラクタを追加すると –
が、私はこのエラーが発生している問題は、次のコンストラクタを追加することによって固定することができます。 "[EclipseLink-4002]:org.eclipse.persistence.exceptions.DatabaseException内部例外:org.postgresql.util.PSQLException:エラー:構文エラーが発生しました«ORDER»位置:13エラーコード:0呼び出し: INSERT INTO ORDER(ID、CREATIONDATE)VALUES(?、?)bind => [2つのパラメータの束縛] Query:InsertObjectQuery(entity.Order [id = 151])at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl。コミット(EntityTransactionImpl.java:157) " –
2番目の問題はない引数なしのコンストラクタで行うこと。私のフランス語は少し錆びますが、ORDERはSQLの予約語です。問題を解決する1つの方法は、テーブル名として予約語を避けることです。それが不可能な場合は、このような問題を解決するための2つの方法があります:http://stackoverflow.com/questions/6791882/jpa-database-delimiters –