WinXP 和 Mac OS X 中的 MySql

发布于 2024-07-25 15:41:26 字数 4713 浏览 8 评论 0原文

我面临着这个奇怪的问题。 我在我的 Win XP 机器上编码,然后将所有代码移至 Mac OS X 机器。 使用 XP 机器上的 jar 运行它。 我正在用 java 编码并使用 hibernate 进行数据库处理。

不知何故,我无法插入一行,而键是使用增量生成器类生成的。 我也在 Mac 上尝试了本机但同样的错误。

这是调试模式。 现在,我知道该错误是密钥违规,但在 WinXP 中不会发生同样的情况。 我在运行代码之前截断数据库。 我认为它们是 Mac 中的一些生成器类依赖项。 或者其他一些罐子?

以下是一些具体信息:

  • Mac OS X 10.5 (x86_64)
  • MYSQL 5.1.35 社区服务器
  • mysql-connector-java-5.1.7-bin.jar JDBC 驱动程序
  • Java(TM) 2 运行时环境,标准版(内部版本 1.5.0_16- b06-284)
  • Java HotSpot(TM) 客户端 VM(版本 1.5.0_16-133,混合模式,共享)

请告知

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

I am facing this bizarre problem.
I am coding on my machine in Win XP and then moving all the code to Mac OS X machine.
Running it using the jars from XP machine.
I am coding in java and using hibernate for database processing.

Somehow I am not able to insert one row, while the keys are generated using the increment generator class. I also tried native but same error on Mac.

here is the debug mode. Now, I know the error as a key violation, but the same doesn't occur in WinXP. I truncate my database before running code. I think their is some generator class dependency in Mac. Or some other jars?

And here are some specifics:

  • Mac OS X 10.5 (x86_64)
  • MYSQL 5.1.35 Community Server
  • mysql-connector-java-5.1.7-bin.jar JDBC driver
  • Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284)
  • Java HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing)

please advise

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

单身情人 2024-08-01 15:41:26

没什么可继续的,但这就是我可以理解的:

  1. 被侵犯的唯一键是标题和语言列上的组合键。 (根据堆栈跟踪中显示的名称(Page_lang_title,其中 lang_id 和 title_id 是列名称)和键的值(1-11266,实际上是两个值的组合)来判断)。
  2. 您维护的页面(请求?)计数 wiki 页面。 这当然容易出现并发问题,因为多个线程(请求)同时访问同一页面。
  3. 您可能正在执行批量更新(或其他操作),并且您已经点击了相同的; 组合两次。 您的逻辑类似于“来自 Page where page_id=? and lang_id=?” 由于您在同一事务中运行批处理并使用 hibernate 进行事务后同步,因此仅在提交事务后才会处理表上的插入,因此您尝试插入 lang_id 和 page_id 的相同组合两次。

现在您可以执行以下操作:

  1. 确保 Hibernate 的 AUTO_FLUSH 模式正常工作,以便每当需要在之前插入新实体时刷新会话对此表进行查询。 为了使这项工作按预期进行,您必须确保 Hibernate 知道已启动的事务。
  2. 维护您自己为每个事务创建的 Pagedatecount 缓存,并在使用 Hibernate 检查数据库之前查询该缓存。

想一想:Pagedatecount 实体不是缺少日期列吗? 它似乎没有被插入。

There is very little to go on, but this is what I can make of it:

  1. The unique key that is being violated is a combined key on the title and language column. (judging from the name (Page_lang_title, where lang_id and title_id are columns name) and the value of the key (1-11266, actually a combination of two values) that is shown in the stacktrace).
  2. Your maintaining a page (request?) count for a wiki page. This is of course prone to concurrency problems, as multiple threads (requests) are accessing the same page at the same time.
  3. Your probably doing a batch update (or something) and you've hit the same <lang_id,title_id> combination twice. Your logic is something like "from Page where page_id=? and lang_id=?" since your running a batch in the same transaction and using hibernate for after transaction synchronization, your insert on the table is only processed after you've committed the transaction and thus you try to insert the same combination of lang_id and page_id twice.

Now there is a few things that you can do:

  1. Make sure that Hibernate's AUTO_FLUSH mode is working correctly, so the session is flushed whenever a new entity needs to be inserted just before a query is made on this table. To make this work as intended, you'll have to make sure that Hibernate is aware of transactions that are started.
  2. Maintain your own cache of Pagedatecount's that you've created per transaction and query that before you check the database with Hibernate.

Come to think of it: Isn't the Pagedatecount entity missing a date column? It is not being inserted it seems.

§对你不离不弃 2024-08-01 15:41:26

我遇到了同样的问题。 不知道你已经解决了没有。 无论如何,就我而言,这是 MySQL 如何创建表并执行表名比较的问题。 在 MacOsX 上,我必须将“lower_case_table_names”MySQL 变量设置为 1(默认情况下为 0),这是使用 InnoDB 时的建议值。 这解决了我的问题(和你一样,Hibernate 似乎没有获取自动生成的 id)。

希望这可能有所帮助,
里卡多.

I run into the same problem. Don't know if you have already solved it. Anyway, in my case it was a problem of how MySQL creates tables and performs table names comparison. On MacOsX I had to set the "lower_case_table_names" MySQL variables to 1 (by default it was 0), which is the suggested value when using InnoDB. And this solved my problem (which, as you, was that it seemed Hibernate was not picking up the autogenerated ids).

Hopes this might help,
Riccardo.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文