我正面临着这个奇怪的问题。 我正在Win XP中的机器上编码,然后将所有代码移动到Mac OS X机器上。 使用XP机器的罐子运行它。 我在java中编码并使用hibernate进行数据库处理。
不知何故,我无法插入一行,而键是使用增量生成器类生成的。我也在Mac上试过原生但同样的错误。
这是调试模式。现在,我知道错误是一个关键违规,但在WinXP中不会发生同样的错误。我在运行代码之前截断了我的数据库。我认为他们是Mac中的一些生成器类依赖。还是其他一些罐子?
以下是一些细节:
2009-06-20 18:43:01,230 DEBUG [org.hibernate.type.IntegerType] - binding '11266' to parameter: 2
2009-06-20 18:43:01,230 DEBUG [org.hibernate.type.IntegerType] - binding '332' to parameter: 3
2009-06-20 18:43:01,281 DEBUG [org.hibernate.type.IntegerType] - binding '6' to parameter: 4
2009-06-20 18:43:01,281 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister] - Inserting entity: [org.joshua.hibernate.dto.Pagedatecounts#289]
2009-06-20 18:43:01,281 DEBUG [org.hibernate.jdbc.AbstractBatcher] - Executing batch size: 1
2009-06-20 18:43:01,288 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2009-06-20 18:43:01,288 DEBUG [org.hibernate.jdbc.AbstractBatcher] - closing statement
2009-06-20 18:43:01,289 DEBUG [org.hibernate.util.JDBCExceptionReporter] - Could not execute JDBC batch update [insert into wiki.page (langId, titleId, totalCounts, id) values (?, ?, ?, ?)]
java.sql.BatchUpdateException: Duplicate entry '1-11266' for key 'Page_lang_title'
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1693)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1108)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:222)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2224)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.joshua.hibernate.dao.PageDAO.batchSave(PageDAO.java:70)
at org.joshua.businesservice.PageServiceImpl.savePageDateCountBatch(PageServiceImpl.java:61)
at org.joshua.wikidumps.DumpHandler.endElement(DumpHandler.java:192)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:375)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:176)
at org.joshua.wikidumps.PagesByNumberOfRecentEdits.execute(PagesByNumberOfRecentEdits.java:107)
at org.joshua.wikidumps.PagesByNumberOfRecentEdits_ur.main(PagesByNumberOfRecentEdits_ur.java:19)
2009-06-20 18:43:01,290 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 1062, SQLState: 23000
2009-06-20 18:43:01,290 ERROR [org.hibernate.util.JDBCExceptionReporter] - Duplicate entry '1-11266' for key 'Page_lang_title'
2009-06-20 18:43:01,290 ERROR [org.hibernate.event.def.AbstractFlushingEventListener] - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
答案 0 :(得分:1)
没有什么可以继续下去,但这就是我能做到的:
现在你可以做一些事情:
AUTO_FLUSH
模式正常工作,因此只要在在此表上进行查询之前需要插入新实体,就会刷新会话。为了使其按预期工作,您必须确保Hibernate知道已启动的事务。来想一想:Pagedatecount实体是不是缺少日期列?它似乎没有被插入。
答案 1 :(得分:1)
我遇到了同样的问题。不知道你是否已经解决了它。无论如何,在我的情况下,这是MySQL如何创建表并执行表名比较的问题。在MacOsX上,我必须将“lower_case_table_names”MySQL变量设置为1(默认情况下为0),这是使用InnoDB时的建议值。这解决了我的问题(就像你一样,Hibernate似乎没有拿起自动生成的ID)。
希望这可能有所帮助, 的Riccardo。