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

inserting through Hibernate

 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Swing with hibernate.

There is a enrollmentNo(long) property of StudentPersonalEntity.
A form is displayed, and it should be saved only if its not in the database table

Enrollmentno 1005 is entered in the form



This code prints "Already exists", but there is no record with 1005 in the database table. I have also tried it with a different value such as 1006675

However, if i try with a value already present in the database, its works fine, and prints "Already exists"

I am more confused, because this code was working fine earlier in the day
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is solved by using 'get' method instead of 'load'

Can anyone tell the reason behind this?

I guess 'get' eagerly fetches, and 'load' fetches it lazily. Is it so?
 
Savannah David
Greenhorn
Posts: 16
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kunal Lakhani wrote:The problem is solved by using 'get' method instead of 'load'

Can anyone tell the reason behind this?

I guess 'get' eagerly fetches, and 'load' fetches it lazily. Is it so?


yes, get() uses "eager loading" i.e. it immediately hits the database and fetches the record whereas laod() works on "lazy loading". A proxy object is created in case of load.
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply Savannah David
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic