This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate: Problems while fetching data due to spaces

 
Gabbar singh
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • 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;

}
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic