MySql on WinXP and Mac OS X

I ran into this strange problem. I encode my machine in Win XP, and then move all the code to Mac OS X. Run using banners from an XP computer. I code in java and use hibernate to process the database.

Somehow I can’t insert one row, and the keys are generated using the class of the increment generator. I also tried a native but same error on a Mac.

here is the debug mode. Now I know the error as a key violation, but the same does not happen in WinXP. I truncated my database before running the code. I think this is some Mac class generator dependency. Or some other banks?

And here are some features:

  • Mac OS X 10.5 (x86_64)
  • MYSQL 5.1.35 Community Server
  • JDBC driver mysql-connector-java-5.1.7-bin.jar
  • Java (TM) 2 runtime, standard version (build 1.5.0_16-b06-284)
  • HotSpot (TM) Java client virtual machine (build 1.5.0_16-133, mixed mode, sharing)

please inform

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 
+4
source share
2 answers

Too little, but I can do it:

  • The only key that is violated is the combined key in the header and language column. (judging by the name (Page_lang_title, where lang_id and title_id are the column name) and the key value (1-11266, actually a combination of two values), which is shown on the stack).
  • Your page content (query?) Is calculated for the wiki page. This, of course, is connected with concurrency problems, since several threads (requests) access the same page at the same time.
  • You are probably doing a batch update (or something else), and you hit the same combination <lang_id, title_id> twice. Your logic is something like "from the page where page_id =? And lang_id =?" since you execute a batch in one transaction and use sleep mode to synchronize transactions, your insert into the table is processed only after you have completed the transaction, and therefore you are trying to insert the same combination of lang_id and page_id twice.

Now there are a few things you can do:

  • Make sure that the Hibernate AUTO_FLUSH mode is working correctly, so the session is cleared whenever a new object needs to be inserted just before the request is executed in this table. To do this as intended, you need to make sure that Hibernate is aware of the transactions that are running.
  • Keep your own Pagedatecount cache created for each transaction and query before checking the database with Hibernate.

Think about it: is there a Pagedatecount element without a date column? It doesn't seem to be inserted.

+1
source

I am facing the same problem. I don’t know if you allowed it. Anyway, in my case, it was a problem of how MySQL creates tables and performs table name comparisons. On Mac OSX, I had to set the MySQL variables "lower_case_table_names" to 1 (the default was 0), which is the recommended value when using InnoDB. And that solved my problem (which, like you, showed that Hibernate did not collect auto-generated identifiers).

Hope this helps, Riccardo.

+1
source

Source: https://habr.com/ru/post/1286526/


All Articles