1

全部。我有以下代码。

  @ManyToMany(targetEntity = com.acs.gs.juror.model.security.SecurityGroup.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
  @JoinTable(name = "REP_DSGN_SEC_GRP_LNK", 
      joinColumns = {@JoinColumn(name = "REPORT_DESIGN_UUID", referencedColumnName = "UUID")}, 
      inverseJoinColumns = {@JoinColumn(name = "SECURITY_GROUP_UUID", referencedColumnName = "UUID")})
  @IndexColumn(name="HIBERNATE_IDX")
  private List<SecurityGroup> groups;  

哪一天开始出现多袋问题。所以我通过将其更改为一组来修复它,因此:

  @ManyToMany(targetEntity = com.acs.gs.juror.model.security.SecurityGroup.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
  @JoinTable(name = "REP_DSGN_SEC_GRP_LNK", 
      joinColumns = {@JoinColumn(name = "REPORT_DESIGN_UUID", referencedColumnName = "UUID")}, 
      inverseJoinColumns = {@JoinColumn(name = "SECURITY_GROUP_UUID", referencedColumnName = "UUID")})
  @IndexColumn(name="HIBERNATE_IDX")
  private Set<SecurityGroup> groups;  

这工作正常,直到我运行我的数据加载器并收到以下错误:

[java] Exception in thread "main" com.acs.gs.juror.dao.FailedInsertException: Unable to save object:ALTF Funds By Case|ALTF Funds By Case Report|java.util.GregorianCalendar[time=18000000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/New_York",offset=-18000000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=America/New_York,offset=-18000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=1970,MONTH=0,WEEK_OF_YEAR=1,WEEK_OF_MONTH=1,DAY_OF_MONTH=1,DAY_OF_YEAR=1,DAY_OF_WEEK=5,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=-18000000,DST_OFFSET=0]|null|ALTFFundsByCase||PDF|[]|Lexptrain|Lexptrain|314||REPORTING|OUTPUT_TYPE|Browser|Browser|Jan 1, 1970 12:00:00 AM||null|null|null|null|null|null|null|null|null|null|null|
[java]  at com.acs.gs.juror.dao.hibernate.HibernateDAO.create(HibernateDAO.java:65)
[java]  at com.acs.gs.juror.dataload.cs.maricopa.LoadReportDesigns.loadData(LoadReportDesigns.java:116)
[java]  at com.acs.gs.juror.dataload.cs.maricopa.SeedDataLoader.loadData(SeedDataLoader.java:48)
[java]  at com.acs.gs.juror.dataload.cs.maricopa.SeedDataLoader.main(SeedDataLoader.java:18)
[java] Caused by: org.springframework.dao.DataIntegrityViolationException: Could not execute JDBC batch update; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
[java]  at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:636)
[java]  at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
[java]  at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
[java]  at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
[java]  at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:694)
[java]  at com.acs.gs.juror.dao.hibernate.HibernateDAO.create(HibernateDAO.java:62)
[java]  ... 3 more
[java] Caused by: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
[java]  at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
[java]  at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
[java]  at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
[java]  at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
[java]  at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:171)
[java]  at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
[java]  at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
[java]  at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
[java]  at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390)
[java]  at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:420)
[java]  ... 6 more
[java] Caused by: java.sql.BatchUpdateException: Cannot insert the value NULL into column 'HIBERNATE_IDX', table 'agilejury-thehl_MC.dbo.REP_DSGN_SEC_GRP_LNK'; column does not allow nulls. INSERT fails.
[java]  at net.sourceforge.jtds.jdbc.JtdsStatement.executeBatch(JtdsStatement.java:947)
[java]  at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)
[java]  at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
[java]  at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
[java]  ... 13 more

我尝试删除 @IndexColumn 条目无济于事。Hibernate 无论如何都会创建该列。如果 hibernate 在没有我映射它的情况下创建它,我没有办法在其中存储一个值,那么它是 null 怎么会有问题呢?

我有点卡在这一点上,不知道如何继续。

谢谢。

4

3 回答 3

1

正如错误清楚地表明的那样。

引起:java.sql.BatchUpdateException:无法将值 NULL 插入列 'HIBERNATE_IDX',表 'agilejury-thehl_MC.dbo.REP_DSGN_SEC_GRP_LNK';列不允许空值。插入失败。

这表示您在集合中的一个SecurityGroup类型元素的字段定义为. 当一个元素被添加到.groupsHIBERNATE_IDXnullgroups

于 2012-09-18T17:01:31.867 回答
0

向我们展示该表的 create table 语句,REP_DSGN_SEC_GRP_LNK我将向您展示您的空限制在哪里。去掉空限制,它不会抱怨它是空的。缺点是你会将空值塞进不应该为空的东西中。

List不允许空值,这可以保护您免受此问题的影响。您将其更改为Set,它允许空值。所以有几个选择:

  1. 修复 Set 中的数据不包含空值。
  2. 放宽对空值的限制。
于 2012-09-18T17:01:27.127 回答
0

看起来这是另一个没人真正理解的 Hibernate 黑盒问题。我最终只是创建了自己的实体而不是加入稳定,这解决了问题。

于 2012-09-21T17:41:07.270 回答