Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate query error

 
Sumer Selvaraj
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm studying Hibernate by my self. I've created a query to check the username & password which are passed through the front end.



This works. But the issue is when I make a change in the database, the results shows the old information where it should show the new information. Further I need to redeploy the project or restart the server in order to show the new data.

Can anyone help me on this?
 
Niraj Jha
Ranch Hand
Posts: 63
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When do you make change in the database?
If you are doing same time while application is running then how it will reflect the changes in data from back end as it has loaded in the session earlier.
 
Sumit Bisht
Ranch Hand
Posts: 331
Python Ruby Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do the changes, but ensure that you update this information through hibernate itself.
That way your entities and their associated cache will be updated first and the changes persisted to the database.
 
Sumer Selvaraj
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Niraj Jha wrote:When do you make change in the database?
If you are doing same time while application is running then how it will reflect the changes in data from back end as it has loaded in the session earlier.


Ya I've changed the value while the programme is running. As per you, I've cleared the session but it didn't work. The new codes are

testHibernate Class



JSP page
 
Volodymyr Lysenko
Ranch Hand
Posts: 511
1
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

If you put java code into jsp page then it is wrong old way. Now it is not good practice. Your jsp page should not contain java code!

You need to understand that entity has three states - transient, persistent and detached. Changes made to entity in persistent state are stored into database when your transaction is committed. I recommend you to pass these free tutorials on hibernate
 
Volodymyr Lysenko
Ranch Hand
Posts: 511
1
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To understand better hibernate objects state you MUST read relevant chapter in hibernate doc
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic