File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hibernate Collection Fetch problem with fixed length CHAR 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 Collection Fetch problem with fixed length CHAR" Watch "Hibernate Collection Fetch problem with fixed length CHAR" New topic
Author

Hibernate Collection Fetch problem with fixed length CHAR

Priya Hota
Greenhorn

Joined: Apr 30, 2008
Posts: 3
I have 2 simple tables called ITEM ( primry key ID CHAR(10)) and BID (FK ITEM_ID CHAR(10) references ID(ITEM)).

Both primary key and foreign keys are CHAR(10)

In the entity I have a bidirectional one to many relationship( Item to Bid [1..N])

Hibernate is not retrieving the list of Bids from Item instance. I am doing eager fetching.The generated sql is just fine but the list is empty.

For Example say ITEM table has got a row with Primary key "ONE"
and BID Table has got 3 rows with BID.ITEM_ID as "ONE"

itemObject.getBids("ONE"); -----> returns an Empty List


How ever if I pad the input with spaces and make its length 10, I can get the Bid collection from Item.

itemObject.getBids("ONE[7 spaces padding]"); -----> returns a list of 3 Bids

I know that this is happening for CHAR datatype, does anyone knows how to solve this?

The detailed source code is in my previous posting in Hibernate forum
http://forum.hibernate.org/viewtopic.php?t=986258&highlight=
"Topic: Hibernate problem with Fixed Length CHAR"
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

Wow, this is interesting.

So, given what we would logically think this in the database:

"abc"

Then, "abc"is not a match.

"       abc" is not a match.

BUT

"abc       " IS a match.

Here's a shot in the dark. Is any part of your application setting BIDI parameters? Some languages read right to left, some left to right? Is there any way your database has a right to left BIDI setting somewhere that is effecting data before it is input into the database?

-Cameron McKenzie
[ April 30, 2008: Message edited by: Cameron Wallace McKenzie ]
Priya Hota
Greenhorn

Joined: Apr 30, 2008
Posts: 3
Thanks Cameron for the quick reply.
My DB is DB2zOS version 8 where all the data with type CHAR are stored as right padded.
Hibernate does not have any problem in doing find by primary key(internally it trims the spaces)

But it is not able to retrieve the associated rows in the other(N side of an 1..N relationship) table.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate Collection Fetch problem with fixed length CHAR
 
Similar Threads
Mapping java.util.List
One to many in a query - EJB QL
Using @JoinColumn VS not using @JoinColumn
Mapping many to one where foreign key is a composite id
Foreign key must have same number of columns as the referenced primary key