• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate: Problems while fetching data due to spaces

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;

}
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Gabbar singh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Would you like to try a free sample? Today we are featuring tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic