Two Laptop Bag*
The moose likes Object Relational Mapping and the fly likes inserting through Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "inserting through Hibernate" Watch "inserting through Hibernate" New topic
Author

inserting through Hibernate

Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
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
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
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

Joined: Jun 07, 2012
Posts: 15

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.


You're never a loser until you quit trying.
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
Thanks for your reply Savannah David
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inserting through Hibernate
 
Similar Threads
Parsing XML to make SOAP call
Null Pointer Exception
Backing Method not Being Called
Jboss does not accept "table-name"...why?
Java & MS Access