1 Reply Latest reply on Sep 12, 2006 7:05 PM by xtia004

    Fail to persist sub class

      I have the following code. CreditCardPayment is inherited from Payment and added some extra fields.

      @Entity
      @Table(name = "PAYMENT")
      @Name("payment")
      @Inheritance(strategy=InheritanceType.JOINED)
      @DiscriminatorColumn(name="PAY_METHOD", discriminatorType=DiscriminatorType.STRING, length=2)
      public class Payment implements java.io.Serializable {
      
       private static final long serialVersionUID = 581797746676908701L;
      
       @TableGenerator(name = "objectIdGen", table = "OP_SEQUENCE_GENERATOR", pkColumnName = "GEN_KEY", valueColumnName = "GEN_VALUE", pkColumnValue = "OBJECT_ID", initialValue = 1, allocationSize = 1)
       @Id
       @GeneratedValue(strategy = GenerationType.TABLE, generator = "objectIdGen")
       @Column(name = "OBJECT_ID", nullable = false)
       private Long objID;
      
       @Column(name = "PAYMENT_CODE", length = 10, nullable = false)
       private String paymentCode;
      
       @Column(name = "PAID_AMOUNT", nullable = false)
       private BigDecimal paidAmount;
      
       @Column(name = "PAID_DATE", nullable = false)
       @Basic @Temporal(TemporalType.DATE)
       private Date paidDate;
      
       @Column(name = "PAY_METHOD", length = 2, nullable = false)
       private String payMethod;
      
       ...
      }
      
      
      
      @Entity
      @Table(name = "CREDITCARD_PAYMENT")
      @Name("creditCardPayment")
      @DiscriminatorValue("CC")
      public class CreditCardPayment extends Payment {
      
       private static final long serialVersionUID = -4171432845137278960L;
      
       @JoinColumn(name = "CREDITCARD_ID")
       @ManyToOne
       private CreditCard creditCard;
      
       @Column(name = "AUTH_CODE", length = 15, nullable = false)
       private String authCode;
      
       @Column(name = "DPS_TXN_REF", length = 31, nullable = false)
       private String dpsTxnRef;
      
       ...
      }



      When I create object of CreditCardPayment using following code and persist it. I got exception:
      Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.oneplace.payment.CreditCardPayment._paymentsBackref

      I have checked I didn't miss any fields. What's the property "paymentsBackref" from and how to set it. Please somebody help me.

      CreditCardPayment payment = new CreditCardPayment();
      payment.setAuthCode(authCode);
      payment.setDpsTxnRef(dpsTxnRef);
      payment.setCreditCard(card);
      payment.setPaymentCode(paymentCode);
      payment.setPaidAmount(getSelectedSum());
      payment.setPaidDate(DateTimeUtil.getCurrentDate());
      payment.setPayMethod(payMethod);
      ...
      em.persist(payment);


        • 1. Re: Fail to persist sub class

          I found the problem was caused by there is one-to-many relationship defined at another entity to Payment, which caused a foreign key created at Payment.

          One point is the exception message is not precise and doesn't make much sense.