aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate: Problems while fetching data due to spaces 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: Problems while fetching data due to spaces" Watch "Hibernate: Problems while fetching data due to spaces" New topic
Author

Hibernate: Problems while fetching data due to spaces

Gabbar singh
Greenhorn

Joined: Nov 23, 2007
Posts: 11
Hi - I am using Hibernate with Java Web Services and Oracle 10g.

I use a method to fetch data for a key passed. (Method below).
However in many cases, it is possible that the data may not be fetched
as the passed Id resides in the database with spaces. I know if you use HQL you can trim the data. But is there any way in this get method, I can do a get for trimmed data?


public Object getRecord(Object obj) throws XYZException {
Object objectWithVersionNumber = null;

try {
Method method = obj.getClass().getDeclaredMethod("getId", null);
objectWithVersionNumber = session.get(obj.getClass(),
(Serializable) method.invoke(obj, null));

*** Exception Handling **********

return objectWithVersionNumber;

}
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

The PK id can have spaces in it? Ouch! Run away,

Anyway, you are using reflection and such that because the database allows ugly data with spaces, then you basically have to live with its problems.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Gabbar singh
Greenhorn

Joined: Nov 23, 2007
Posts: 11
hi mark - PK can have spaces as 'AB '. So if a get is done for 'AB', it would not fetch 'AB '.

the PK and related data are loaded by a batch program. I know we can trim the spaces before we load the data. But is there any other solution.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Originally posted by Gabbar singh:
hi mark - PK can have spaces as 'AB '. So if a get is done for 'AB', it would not fetch 'AB '.

the PK and related data are loaded by a batch program. I know we can trim the spaces before we load the data. But is there any other solution.


This is legacy data that can't use a different pk, like a number.

Unfortunately this is a problem directly with the database and not Hibernate. I would fix your database as a first choice.

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate: Problems while fetching data due to spaces