aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate objects into JComboBox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate objects into JComboBox" Watch "Hibernate objects into JComboBox" New topic
Author

Hibernate objects into JComboBox

Sebastiaan Kortleven
Ranch Hand

Joined: Mar 12, 2004
Posts: 81
Hi there,

I've got a strange problem.. I'm using Hibernate to load some objects (Table objects) from my database, the list that is generated is given to a JComboBox for the user to select one.
A table is unique by its row_id. So the equals method of the Table object only looks at the row_id.

When the data is loaded into the ComboBox, the user can't select another object (always returns to the first one). Turned out this was because of the Table that was passed to the equals method always had a row_id of null.

Perhaps some code:

Loading the objects from the database and adding it to the box (this is ofcourse a simplified version):



The equals method of the Table object:






It's here to the table.row_id is null when Swing is checking the objects in the JComboBox..

If I try this the result is the same:



I get false, and the row_id of the list.get(2) is still null (changing the object that is passed to another table (like list.get(4)) doesn't change anything.. Manually creating Table objects works just fine..

What is Hibernate doing to my objects?
Sebastiaan Kortleven
Ranch Hand

Joined: Mar 12, 2004
Posts: 81
changing the table.row_id in the equals method to table.getRow_id() fixed the problem..
Alexandru Popescu
Ranch Hand

Joined: Jul 12, 2004
Posts: 995
This is an indication that you are using lazy loading .

./pope


blog - InfoQ.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate objects into JComboBox