休眠 SQL 引用异常



今天我试图使用休眠注释将客户添加到数据库中,但我不知道为什么我面临表的参考问题!

请阅读下面的例外情况

错误:参照完整性约束冲突:

"FKOFMCQE0O4K2TFOXB308SKTMQ3:公开。国外客户 键(CUS_BILLINGADDRESSID)引用 公共。客户账单地址(CUS_BILLINGADDRESSID)("CBA00001")";.SQL 陈述: 更新客户集 cus_emailid=?, cus_mobileno=?, cus_name=?, cus_billingaddressid=?, cus_cartid=?, cus_loginid=?, cus_shippingaddressid=?其中cus_id=?[23506-193] Apr 01, 2017 7:09:57 PM org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl release 信息: HHH000010:在批处理发布时,它仍然包含 JDBC 语句 Apr 01, 2017 7:09:57 PM org.hibernate.internal.ExceptionMapperStandardImpl 映射管理刷新失败 错误: HHH000346: 托管刷新期间出错 [org.hibernate.exception.ConstraintViolationException: 无法 执行语句] Apr 01, 2017 7:09:57 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE:Servlet.service() for servlet [dispatcher] 在路径 [/TechNXT] 的上下文中抛出了异常 [请求处理失败;嵌套 exception is javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: 不能 执行语句]与根本原因 org.h2.jdbc.JdbcSQLException: Referential integrity constraint Breach : "FKOFMCQE0O4K2TFOXB308SKTMQ3: PUBLIC.国外客户 键(CUS_BILLINGADDRESSID)引用 公共。客户账单地址(CUS_BILLINGADDRESSID)("CBA00001")";.SQL 陈述: 更新客户集 cus_emailid=?, cus_mobileno=?, cus_name=?, cus_billingaddressid=?, cus_cartid=?, cus_loginid=?, cus_shippingaddressid=?其中cus_id=?[23506-192] at org.h2.message.DbException.getJdbcSQLException(DbException.java:345) at org.h2.message.DbException.get(DbException.java:179) at org.h2.message.DbException.get(DbException.java:155) at org.h2.constraint.ConstraintReferential.checkRowOwnTable(ConstraintReferential.java:372) at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:314) at org.h2.table.Table.fireConstraint(Table.java:967) at org.h2.table.Table.fireAfterRow(Table.java:985) at org.h2.command.dml.Update.update(Update.java:151) at org.h2.command.CommandContainer.update(CommandContainer.java:98) at org.h2.command.Command.executeUpdate(Command.java:258) at org.h2.server.TcpServerThread.process(TcpServerThread.java:344) at org.h2.server.TcpServerThread.run(TcpServerThread.java:158) at java.lang.Thread.run(未知来源)

这是我的两个模型表 注意:我已经生成了getter和seters,但没有发布,因此尽可能小 1. 具有其他表引用的客户表

@Entity
public class Customer {
@Id
private String cus_id;
private String cus_name;
private String cus_emailid;
private String cus_mobileno;
@OneToOne(cascade=CascadeType.REFRESH)
@JoinColumn(name="cus_loginid")
private CustomerDetails customerdetails;
@OneToOne(cascade=CascadeType.REFRESH)
@JoinColumn(name="cus_billingaddressid")
private CustomerBillingAddress customerbillingaddress;
@OneToOne(cascade=CascadeType.REFRESH)
@JoinColumn(name="cus_shippingaddressid")
private CustomerShippingAddress customershippingaddress;
@OneToOne(cascade=CascadeType.REFRESH)
@JoinColumn(name="cus_cartid")
private CustomerCart customercart;
  1. 我的客户帐单地址模型

    @Entity 公共类客户计费地址 {

    @Id
    private String cus_billingaddressid;
    private String cus_houseno;
    private String cus_street;
    private String cus_area;
    private String cus_city;
    private String cus_state;
    private String cus_country;
    private String cus_pincode;
    @OneToOne(mappedBy="customerbillingaddress")
    private Customer customer;
    

类似其他模型

最后是将客户添加到数据库的我的DAO方法

这是代码!

@Transactional
public String addCustomer(Customer customer) {
System.out.println("CustomerDao -TechNXTn");
Session ses = sf.openSession();
customer.setCus_id(generateCustomerid());
customer.setCustomerbillingaddress(new CustomerBillingAddress());
customer.setCustomershippingaddress(new CustomerShippingAddress());
customer.setCustomercart(new CustomerCart());
customer.getCustomerdetails().setCus_loginid(generateCustomerLoginid());
customer.getCustomerbillingaddress().setCus_billingaddressid(generateCustomerBillingid());
customer.getCustomershippingaddress().setCus_shippingaddressid(generateCustomershippingid());
customer.getCustomercart().setCus_cartid(generateCustomerCartid());
customer.getCustomerdetails().setCus_isenabled(true);
customer.getCustomerdetails().setCus_role("ROLE_USER");
Transaction tr = ses.beginTransaction();
ses.save(customer);
tr.commit();
ses.close();
return customer.getCustomerdetails().getCus_loginid();
}

好吧,我从 3 小时开始一直在尝试东西,但未能找到解决方案! 很抱歉占用了您宝贵的时间。 并提前感谢您对我的帮助!

你能在你的类上标记@Table

吗喜欢

@Table(name ="Customer")

最新更新