java组织。冬眠例外ConstraintViolationException:无法执行JDBC批处理更新&ORA02289:序列不存在
这是我的pojo课程
package com.sathya.entity;
public class Customer { private String customerId; private String customerName; private String location; public Customer() {} public Customer(String customerId) { this.customerId=customerId;
} public Customer(String customerId,String customerName,String location) { this.customerId=customerId; this.customerName=customerName; this.location=location; } public String getCustomerId() { return customerId; } public void setCustomerId(String customerId) { this.customerId = customerId; } public String getCustomerName() { return customerName; } public void setCustomerName(String customerName) { this.customerName = customerName; } public String getLocation() { return location; } public void setLocation(String location) { this.location = location; } public String toString() { return "Customer["+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:无法将NULL插入(“系统”、“客户”、“客户ID”)
*
# 1 楼答案
您应该手动或通过自动策略设置ID。你可以使用Oracle,也可以使用序列