org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
packagecom.handsomeming.hibernate.model;importjavax.persistence.Entity;importjavax.pe...
package com.handsomeming.hibernate.model;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
@Entity
@Table(name="student")
public class Student {
private int id;
private String name;
private String sex;
private String FcukMan;
@Id
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
@Transient
public String getFcukMan() {
return FcukMan;
}
public void setFcukMan(String fcukMan) {
FcukMan = fcukMan;
}
}
public class StudentTest {
static Configuration cfg;
static Session session;
static SessionFactory sf;
@BeforeClass
public static void conf() {
cfg = new AnnotationConfiguration().configure();
}
@Test
public void test() {
Student s = new Student();
s.setId(4);
s.setName("111");
s.setSex("23");
s.setFcukMan("3ck");
sf = cfg.buildSessionFactory();
session = sf.openSession();
session.save(s);
session.beginTransaction().commit();
}
@AfterClass
public static void close() {
session.close();
sf.close();
}
}
本来是好的 加了log4j后就报错了 难道是log4j.properties出错? 而且我也没添加约束 展开
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
@Entity
@Table(name="student")
public class Student {
private int id;
private String name;
private String sex;
private String FcukMan;
@Id
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
@Transient
public String getFcukMan() {
return FcukMan;
}
public void setFcukMan(String fcukMan) {
FcukMan = fcukMan;
}
}
public class StudentTest {
static Configuration cfg;
static Session session;
static SessionFactory sf;
@BeforeClass
public static void conf() {
cfg = new AnnotationConfiguration().configure();
}
@Test
public void test() {
Student s = new Student();
s.setId(4);
s.setName("111");
s.setSex("23");
s.setFcukMan("3ck");
sf = cfg.buildSessionFactory();
session = sf.openSession();
session.save(s);
session.beginTransaction().commit();
}
@AfterClass
public static void close() {
session.close();
sf.close();
}
}
本来是好的 加了log4j后就报错了 难道是log4j.properties出错? 而且我也没添加约束 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询