- This topic has 8 replies, 3 voices, and was last updated 17 years, 11 months ago by
Riyad Kalla.
-
AuthorPosts
-
ahmettahaMemberI have followed the hibernate and Spring tutorial. I am able to select rows from the database, how ever I can not add. I get the following error:
I have searched this error code and apperantly it is
#1205 (ER_LOCK_WAIT_TIMEOUT)
Lock wait timeout expired. Transaction was rolled back.
What am I missing? Normally I should copy and paste code, but i had just followed the tutorial, and nothing more.
org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: Could not execute JDBC batch update; uncategorized SQLException for SQL [insert into patix.User (name, email, password, id) values (?, ?, ?, ?)]; SQL state [HY000]; error code [1205]; Lock wait timeout exceeded; try restarting transaction; nested exception is java.sql.BatchUpdateException: Lock wait timeout exceeded; try restarting transaction org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.translate(SQLStateSQLExceptionTranslator.java:120) org.springframework.orm.hibernate3.HibernateAccessor.convertJdbcAccessException(HibernateAccessor.java:424) org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:410) org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:377) org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:632) com.patix.hibernate.UserDAO.save(UserDAO.java:32) com.patix.hibernate.PersistenceLayer.addUser(PersistenceLayer.java:15) org.apache.jsp.index_jsp._jspService(index_jsp.java:73) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
June 19, 2007 at 11:14 am #271731
Riyad KallaMemberI’ve never seen this before, I googled for it and came across this on the Hibernate forums:
http://forum.hibernate.org/viewtopic.php?p=2337160seems like it was something very silly that fixed it, which could explain why I’ve never seen it…
June 19, 2007 at 1:02 pm #271745
ahmettahaMemberThanks, I’ll rebuild some stuff to see if it will fix it. I had the same setup without the spring capabilities, and everything worked out fine. Which makes me think? What is the adventage of using spring with hibernate? I have just read that It makes things easier, and since I’m new to these stuff, I just followed the tutorial. Could you tell me what is the benefit of using spring with hibernate instead of just hibernate?
Thanks
June 19, 2007 at 1:13 pm #271749
Riyad KallaMemberI have just read that It makes things easier, and since I’m new to these stuff, I just followed the tutorial. Could you tell me what is the benefit of using spring with hibernate instead of just hibernate?
Ok take this with a grain of salt, but folks seem to be split on Spring… I’ve never seen it as the silver-arrow that some folks see it as. It’s handy for things like swapping in mock objects easily during testing and fake data sources and stuff like that… but I actually think because of all the “magic injection” it does, it makes following the structure of larger apps much harder.
although I have friends and feel the opposite and think it’s better than fire and water… so it’s hard to say.
I would probably suggest if you are getting strated with all these technologies, try and get the app working first, and add in Spring later if you need it. Otherwise just put that effort towards getting your app to work just how you want it.
June 19, 2007 at 2:02 pm #271761
ahmettahaMemberThank you. Like for example, I have rebuilt some stuff, and it works now. I dont get that stupid error anymore. However, I have another problem. Which is committing. The changes dont commit. I dont want to add autocommit to hibernate config as it is not recommended, and I cant find a way to make the data commit after the change in UserDAO. what do I need to add and where do I need to add a commit call.
June 19, 2007 at 2:04 pm #271762
Riyad KallaMemberAhh the commit is actually occuring inside the Hibernate Session, and it’s up to Hibernate to decide when to persist that to the physical DB.
If you want to force it to commit, you can use a transaction. Begin the transaction before the operation (like save) then commit it after, and it will be stored in the DB.
JPA does the same thing.
It ends up looking something like:
//Begin Transaction
dao.save(myObject);
//Commit TransactionJune 19, 2007 at 2:22 pm #271764
ahmettahaMemberso what you are saying is at one point when hibernate decides, it will commit. Interesting.
About your answer for using spring and hibernate. I didnt quite understand what you mean. Before reading about spring, I had everything generated by myeclipse as I did now. and all I have seen so far is, I had created some beans that I dont understand what they do. and I have created a persistant layer. I dont quite get the purpose of these, and the tutorial here doesnt really explain it.
before spring I was using:
UserDAO dao = new UserDAO(); dao.save(newUser);
with spring it is
persistantLayer.addUser(newUser);
and persistantLayer is doing what I was doing without spring.
July 24, 2007 at 9:46 am #273093
gogo543Member//Begin Transaction
dao.save(myObject);
//Commit Transactionsorry i am a beginner hibernate and spring user ….
I follow the tutorial and i run into the same problem as ahmettaha.
after reading your reply … do you mind to give me an example?July 24, 2007 at 1:00 pm #273124
Riyad KallaMemberso what you are saying is at one point when hibernate decides, it will commit. Interesting.
Yes, if you don’t force it. It manages the session.
and persistantLayer is doing what I was doing without spring.
Sorry about that… the tutorial is a bit contrived to keep it simple BUT still show what Spring does. In a real application, you likely wouldn’t have used Spring in such a simple app.
-
AuthorPosts