This week's book giveaway is in the Spring forum. We're giving away four copies of Java Persistence with Spring Data and Hibernate and have Cătălin Tudose on-line! See this thread for details.
I am developing a web application with Struts, Spring and Hibernate with JBoss 4.4.2 GA app server and MySQL.
I have a strange issue. I am just filling up the form and submitted for storing in DB and I can able to see the insert query (hibenate) in console and success message.
When I quering at table, that record is not found. I am again tried to fill up the form with different data and submitted and wehn I queried the table, I can able to see the old record which I have filled previously , but the new one is not found.
Like wise, whenever I am filling up the form and submitted, I can able to see the old record and but the newly added one is NOT found.
any parameter/configuration setting needs to be done for this
Has the insert been commited? Looks like you are querying the table from outside the transaction before it has been commited. And since the Transaction is isolated, only inside the transaction would you see the record, until after it has been commited.
Actually the insertion is happening inside the transaction and also commit it. I am checking the DB directly using MySQL Client to check whether it has been inserted or not. I am not checking(select query) it in hibernate txn.
I will send the coding shortly. thanks.
That's kind of what I meant, since you are checking outside the code, you are looking before the transaction has been committed, and therefore isolated to inside the transaction, and outside it is isolated from seeing it.
Below is the coding I am using for DAO. In that, I am staring the transaction, save it to DB and also commiting the txn and the control return backs to struts action and forward it to jsp. How to know whether the transaction is completed or not? I have attached the log from the console. Please advice.
Now, whatever I am saving is not storing in DB. I could able to see the hibernate insert query, but it's not storing in DB.
What version of Hibernate are you using? Are you using 2.x? If so, then what I say here you can ignore, but if you are using Hibernate 3.x...
"HibernateDaoSupport" was created for older versions of Hibernate to help with a few things and to work with the HibernateTemplate. In Hibernate 3.x, these classes should not be used.
1) They tie your code (tightly coupled) to Spring specific classes because you are extending one of their classes.
2) You no longer have to manage transactions yourself.
3) Hibernate SessionFactory now has getCurrentSession(), which returns a Session that is tied to your ThreadLocal, so now Transactional boundaries can be placed in their best corresponding location, at your service level.
code can now look like
Now I wouldn't have the saveUserPojo method return a UserPojo, because all you are doing is returning the parameter. which you already have a reference to in your calling code.
Yes, I am using hibernate 3.0. I will try to do as per your suggestion though I am new to annotations. thanks for your help. I will come back if I have any doubts,
Yes, I am using hibernate 3.0. I will try to do as per your suggestion though I am new to annotations. thanks for your help. I will come back if I have any doubts,
The code wouldn't change, but you can do everything I did with Annotations with xml, it is just more typing and to get something posted quickly I used annotations.
I will try to use the Annotations as suggested by you and thanks for your help. Can you please help to suggest what went wrong in the below procedure ?
or can you please advice me some of the url/tutorial on how to use the annotations with the example?
I am struggling with the below insertion into db using Struts 1.3 - Spring 2 - Hibernate 3.0.
I can able to see the hibernate insert log in console, but while querying the db no record id found.
Please help to advice what is the issue in my below codings. I am suspecting the issuew is with the configuration.
Can anyone help on this? Is there any issue with applicationContext/hibernate.cfg.xml or in some where else?
My issue is, it's not getting stored in DB but I am not getting any error/exception. PLease help to advice. thanks.
Is that the console log, or the actual
Tomcat" log, which has more detail?
There must be some rollback happening in your code, maybe an exception that is in the server's log file and not the console.
Are you stuck with using Hibernate 3.0 instead of a newer version?
Also, you are using the HibernateTemplate and HibernateDaoSupport, which I would use for Hibernate 2.x but not for Hibernate 3.x
With 3.x I just inject the SessionFactory into the Repository/DAO and call getCurrentSession(). and call methods on Session. You no longer have to do sessio.beginTransation() commit() or rollback() the transaction manager handles that for you. But that isn't something you should change to right now, just so that you can see it save.
I am using JBoss 4.2.2GA and I couldn't able to see any exception/error in server.log/jboss console. Only for the runtime exception the txn will rollback and how could any exception/error log found?
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!