Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to find the added record in table.

 
Mike Thomson
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

For Example:

adding emp id: 1

emp table:
=========
No data

adding emp id: 2

emp table:
=========
1


adding emp id: 3

emp table:
=========
1
2






 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Mark
 
Mike Thomson
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark,

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.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Mark
 
Mike Thomson
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Mark,

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.



 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Mark
 
Mike Thomson
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark,

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,
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Thomson wrote:Mark,

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.

Mark
 
Mike Thomson
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark,

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.

UserAction
==========



UserService:
=============


UserHelper:
===========


applicationContext:
===================


hibernate.cfg.xml:
===================


User.hbm.xml:
==============


Table:
=======


Log:
====
 
Mike Thomson
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Mark
 
Mike Thomson
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic