Hi i have a table in which i am not using Hibernate ID generator but instead using a method to generate a random number(this will never be same as per logic). Is this a bad approach?
I have a method which first loads this table entity using select query and then updates some columns in the entity object returned and saves it. This is happening in the same session the load and update. In this case sometimes i get an exception:-
2014-05-20 11:31:16,341 | ERROR | [http-10181-3] |org.hibernate.util.JDBCExceptionReporter:logExceptions(101) | Lock wait timeout exceeded; try restarting transaction
2014-05-20 11:31:16,344 | ERROR | [http-10181-3] |org.hibernate.event.def.AbstractFlushingEventListener:performExecutions(324) | Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
This comes when this method is called a lot of times. i.e my application is being used by multiple users. Any pointers on this? Is the approach being used my me for manually assiging ID incorrect? Or this has nothing to do with it?
Similarly in some cases i am also querying the table to get the next ID: like select max(id) and then set the id for the next row? Is this also a bad approach?
PS: The id column is a primary key and the DB being used is MySQL