小编Red*_*a N的帖子

无法执行JDBC批量更新:线程"main"中的异常org.hibernate.exception.ConstraintViolationException:

我是hibernate编程的新手请帮帮我,执行下面的文件时遇到问题.我正在使用MySQL数据库.我的错误是

SLF4J:无法加载类"org.slf4j.impl.StaticLoggerBinder".SLF4J:默认为无操作(NOP)记录器实现SLF4J:有关更多详细信息,请参阅http://www.slf4j.org/codes.html#StaticLoggerBinder.Hibernate:插入UserDetails(userName)值(?)Hibernate:插入UserDetails(userName)值(?)Hibernate:插入UserDetails(userName)值(?)Hibernate:插入车辆(vehiName)值(?)Hibernate:插入车辆(vehiName)值(?)Hibernate:插入UserDetails_vehicle(UserDetails_userID,vehi_vehiID)值(?,?)Hibernate:插入UserDetails_vehicle(UserDetails_userID,vehi_vehiID)值(?,?)Hibernate:插入UserDetails_vehicle(UserDetails_userID, vehi_vehiID)值(?,?)

异常在线程"主要" org.hibernate.exception.ConstraintViolationException:无法在org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)在org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper执行JDBC批处理更新.的java:66)在org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)在org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:268)在org.hibernate.engine.ActionQueue.executeActions(ActionQueue的.java:188)处org.hibernate.impl在org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51 org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)). SessionImpl.flush(SessionImpl.java:1216)在org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)在org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)在com.annt.java .UserTest.main(UserTest.java:34)引起:java.sql.BatchU pdateException:复制在org.hibernate作为条目 '1' 为键 'vehi_vehiID' 在com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1669)在com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1085) .jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)在org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)... 8个

UserDetails.java

@Entity
public class UserDetails {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int userID;
    @OneToMany
    private List<vehicle> vehi = new ArrayList<vehicle>();

    public List<vehicle> getVehi() {
        return vehi;
    }

    public void setVehi(List<vehicle> vehi) {
        this.vehi = vehi;
    }

    public int getUserID() {
        return userID;
    }

    public void setUserID(int userID) {
        this.userID = userID;
    }
    private String userName;

    public String getUserName() {
        return userName;
    }

    public …
Run Code Online (Sandbox Code Playgroud)

java mysql hibernate

2
推荐指数
1
解决办法
5万
查看次数

标签 统计

hibernate ×1

java ×1

mysql ×1