简体   繁体   English

org.hibernate.propertyvalueexception not-null属性引用null

[英]org.hibernate.propertyvalueexception not-null property references a null

im new to JPA, i got the error above when trying to persist the transaction data. 我是JPA的新手,在尝试保留事务数据时遇到了以上错误。

Here's my Entity: 这是我的实体:

  @Entity
  @Table(name = "transaction1")
  @NamedQueries({
  @NamedQuery(name = "Transaction1.findAll", query = "SELECT t FROM Transaction1 t"),
  @NamedQuery(name = "Transaction1.findByTransactionID", query = "SELECT t FROM Transaction1 t WHERE t.transactionID = :transactionID"),
  @NamedQuery(name = "Transaction1.findByAmount", query = "SELECT t FROM Transaction1 t WHERE t.amount = :amount"),
  @NamedQuery(name = "Transaction1.findByFromAccNo", query = "SELECT t FROM Transaction1 t WHERE t.fromAccNo = :fromAccNo"),
  @NamedQuery(name = "Transaction1.findByFromSortCodeNo", query = "SELECT t FROM Transaction1 t WHERE t.fromSortCodeNo = :fromSortCodeNo"),
  @NamedQuery(name = "Transaction1.findByName", query = "SELECT t FROM Transaction1 t WHERE t.name = :name"),
  @NamedQuery(name = "Transaction1.findByToAccNo", query = "SELECT t FROM Transaction1 t WHERE t.toAccNo = :toAccNo"),
  @NamedQuery(name = "Transaction1.findByToSortCodeNo", query = "SELECT t FROM Transaction1 t WHERE t.toSortCodeNo = :toSortCodeNo"),
  @NamedQuery(name = "Transaction1.findByTransactionDate", query = "SELECT t FROM Transaction1 t WHERE t.transactionDate = :transactionDate")})
public class Transaction1 implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "Transaction_ID")
private Integer transactionID;
@Basic(optional = false)
@Column(name = "Amount")
private double amount;
@Basic(optional = false)
@Column(name = "From_Acc_No")
private int fromAccNo;
@Basic(optional = false)
@Column(name = "From_Sort_Code_No")
private String fromSortCodeNo;
@Basic(optional = false)
@Column(name = "Name")
private String name;
@Basic(optional = false)
@Column(name = "To_Acc_No")
private int toAccNo;
@Basic(optional = false)
@Column(name = "To_Sort_Code_No")
private String toSortCodeNo;
@Basic(optional = false)
@Column(name = "Transaction_Date")
@Temporal(TemporalType.TIMESTAMP)
private Date transactionDate;
static EntityManagerFactory emf = Persistence.createEntityManagerFactory("SWSXXPU");
public Transaction1() {
}

public Transaction1(Integer transactionID) {
    this.transactionID = transactionID;
}

public Transaction1(Integer transactionID, double amount, int fromAccNo, String fromSortCodeNo, String name, int toAccNo, String toSortCodeNo, Date transactionDate) {
    this.transactionID = transactionID;
    this.amount = amount;
    this.fromAccNo = fromAccNo;
    this.fromSortCodeNo = fromSortCodeNo;
    this.name = name;
    this.toAccNo = toAccNo;
    this.toSortCodeNo = toSortCodeNo;
    this.transactionDate = transactionDate;
}

public Integer getTransactionID() {
    return transactionID;
}

public void setTransactionID(Integer transactionID) {
    this.transactionID = transactionID;
}

public double getAmount() {
    return amount;
}

public void setAmount(double amount) {
    this.amount = amount;
}

public int getFromAccNo() {
    return fromAccNo;
}

public void setFromAccNo(int fromAccNo) {
    this.fromAccNo = fromAccNo;
}

public String getFromSortCodeNo() {
    return fromSortCodeNo;
}

public void setFromSortCodeNo(String fromSortCodeNo) {
    this.fromSortCodeNo = fromSortCodeNo;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public int getToAccNo() {
    return toAccNo;
}

public void setToAccNo(int toAccNo) {
    this.toAccNo = toAccNo;
}

public String getToSortCodeNo() {
    return toSortCodeNo;
}

public void setToSortCodeNo(String toSortCodeNo) {
    this.toSortCodeNo = toSortCodeNo;
}

public Date getTransactionDate() {
    return transactionDate;
}

public void setTransactionDate(Date transactionDate) {
    this.transactionDate = transactionDate;
}

@Override
public int hashCode() {
    int hash = 0;
    hash += (transactionID != null ? transactionID.hashCode() : 0);
    return hash;
}

@Override
public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof Transaction1)) {
        return false;
    }
    Transaction1 other = (Transaction1) object;
    if ((this.transactionID == null && other.transactionID != null) || (this.transactionID != null && !this.transactionID.equals(other.transactionID))) {
        return false;
    }
    return true;
}

@Override
public String toString() {
    return "Entities.Transaction1[transactionID=" + transactionID + "]";
}

Here's my servlet: 这是我的servlet:

   try{

         Transaction1 t = new Transaction1();

         t.setFromAccNo(youraccinput);
         t.setFromSortCodeNo(yoursortcodeinput);
         t.setToAccNo(toaccinput);
         t.setToSortCodeNo(destsortcodeinput);
         t.setName(recname);
         t.setAmount(amtsender);

         EntityManager em;
         EntityManagerFactory emf;
         try {
              emf = Persistence.createEntityManagerFactory("SWSXXPU");
              em = emf.createEntityManager();
              em.getTransaction().begin();
              em.persist(t);
              em.getTransaction().commit();
              request.getRequestDispatcher("ListTransaction").forward(request, response);
         }
         catch(Throwable e){
              out.print(e.getMessage());
              out.print(e.getCause());
          }
         Accounts.debitSourceAccBalance(youraccinput, toaccinput, recname, amtsender);
         }
         catch(Throwable e){
             out.print(e.getMessage());
             out.print(e.getCause());
         }

Full error message: 完整的错误消息:

org.hibernate.PropertyValueException: not-null property references a null or transient value: Entities.Transaction1.transactionDateorg.hibernate.PropertyValueException: not-null property references a null or transient value: Entities.Transaction1.transactionDate org.hibernate.PropertyValueException:非空属性引用一个空值或瞬态值:Entities.Transaction1.transactionDateorg.hibernate.PropertyValueException:非空属性引用一个空值或瞬态值:Entities.Transaction1.transactionDate

I debugged it and it seemed like there is a value property of not null is null, which i dont seem to understand this error message. 我调试了它,似乎有一个不为null的value属性为null,我似乎不理解此错误消息。 I thought I dont need to persist transactionID, as it is set to autoincrement, and transactionDate to timestamp oncurrentupdate. 我以为我不需要持久化transactionID,因为它设置为autoincrement,而transactionDate设置为oncurrentupdate的时间戳。 Can anyone please kindly help to fix? 谁能帮忙解决一下吗?

The transactionDate field has been marked with @Basic(optional = false) . transactionDate字段已用@Basic(optional = false)标记。 Ensure that the value for this field is not null while persisting the Transaction. 在保留事务时,请确保此字段的值不为null。

If the transactionData can be genuinely null (I guess not), you can remove the optional option from @Basic . 如果transactionData可以真正为null(我想不是),则可以从@Basic删除optional选项。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Hibernate异常org.hibernate.PropertyValueException:not-null属性引用了null或瞬态值 - Hibernate exception org.hibernate.PropertyValueException: not-null property references a null or transient value org.hibernate.PropertyValueException:非空属性在使用 Spring 引导时引用 null 或瞬态值 - org.hibernate.PropertyValueException: not-null property references a null or transient value while using Spring Boot 与问题相关的hibetnate获取“ org.hibernate.PropertyValueException”非null属性引用null - Issue related hibetnate getting “org.hibernate.PropertyValueException” not-null property references a null 尝试发布时出错:org.hibernate.PropertyValueException:非空属性引用 null 或瞬态值 - Getting error while trying to post: org.hibernate.PropertyValueException: not-null property references a null or transient value org.hibernate.PropertyValueException:not-null属性引用一个null或瞬态值:mdl.Complaint.jobDone - org.hibernate.PropertyValueException: not-null property references a null or transient value: mdl.Complaint.jobDone 线程“ main” org.hibernate.PropertyValueException中的异常:not-null属性引用了null或瞬态值 - Exception in thread “main” org.hibernate.PropertyValueException: not-null property references a null or transient value org.hibernate.PropertyValueException:not-null属性引用一个空值或瞬态值:com.rasvek.cms.entity.State.country - org.hibernate.PropertyValueException: not-null property references a null or transient value : com.rasvek.cms.entity.State.country 当我提交表单时,我收到此错误 org.hibernate.PropertyValueException: not-null property references a null 或瞬态值 - When I submit the form I get this error org.hibernate.PropertyValueException: not-null property references a null or transient value org.hibernate.PropertyValueException - org.hibernate.PropertyValueException 休眠异常“ PropertyValueException:非null属性引用> null或瞬时值”。 我被困住了,不知道该怎么办 - Hibernate exception “PropertyValueException: not-null property references a > null or transient value”. I am stuck and don't know what to do
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM