【问题标题】:org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update&ORA-02289: sequence does not existorg.hibernate.exception.ConstraintViolationException: 无法执行 JDBC 批量更新&ORA-02289: 序列不存在
【发布时间】:2018-01-09 15:53:30
【问题描述】:

这是我的 pojo 课

包 com.sathya.entity;

公共类客户{私人字符串客户ID;私有字符串 顾客姓名;私有字符串位置;公共客户(){} 公共客户(字符串 customerId){ this.customerId=customerId;
} 公共客户(字符串客户ID,字符串客户名称,字符串 位置) { this.customerId=customerId; this.customerName=客户名称;这个位置=位置; } 上市 String getCustomerId() { return customerId; } 公共无效 setCustomerId(String customerId) { this.customerId = customerId; } public String getCustomerName() { return customerName; } 上市 无效 setCustomerName(String customerName) { this.customerName = 顾客姓名; } public String getLocation() { 返回位置; } 公共无效 setLocation(字符串位置){ this.location = 地点; } 公共字符串 toString() { 返回 "客户["+customerId+","+customerName+","+location+"]"; } }

我的客户程序是

>         package com.sathya.test;
>     
>     
>     
>     import org.hibernate.Session;
>     import org.hibernate.SessionFactory;
>     import org.hibernate.Transaction;
>     import org.hibernate.cfg.Configuration;
>     
>     import com.sathya.entity.Customer;
>     
>     public class InsertCustomer {
>     
>       public static void main(String[] args) 
>       {
>           Configuration config=new Configuration();
>           config.configure("com/sathya/config/hibernate.cfg.xml");
>           SessionFactory factory=config.buildSessionFactory();
>           Session session=factory.openSession();
>           Customer cust=new Customer();
>           cust.setCustomerName("sathya");
>           cust.setLocation("Hyd");
>           Transaction tx=session.beginTransaction();
>           session.save(cust);
>           tx.commit();
>           session.close();
>           factory.close();
>       }
>     
>     }

*

在尝试执行程序时出现 ORA-01400: cannot insert NULL into ("SYSTEM"."CUSTOMER"."CUSTOMERID") 等错误

*

【问题讨论】:

    标签: java hibernate


    【解决方案1】:

    您应该手动或通过自动策略设置 ID。你使用 Oracle,你可以使用序列。

    【讨论】:

    • 您手动调用 cust.setCustomerID 或在休眠映射文件中设置实体以使用 oracle 序列
    猜你喜欢
    • 2011-04-05
    • 2012-07-30
    • 1970-01-01
    • 2014-02-15
    • 2012-10-01
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多