-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 
Author Message
 Post subject: Char padding
PostPosted: Mon Feb 02, 2004 1:23 pm 
Newbie

Joined: Thu Jan 29, 2004 5:27 pm
Posts: 5
I have an existing database that i cannot change, unfortunately
they have used CHAR instead of VARCHAR, so we
are going to have to code around padding
issues.

I attempted to remedy this by using a view and using
TRIM to get rid of the padding, however when I do
an insert on the trimmed fields I get:

[WARN] JDBCExceptionReporter - -SQL Error: 1733, SQLState: 42000
[ERROR] JDBCExceptionReporter - -ORA-01733: virtual column not allowed here

I take this to mean that when trimimming those fields the database lost
the link to the underlying table. If I remove the trim statments
from the view inserts work correctly.

Any Ideas? Strategies to get around this issues?

Raj


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 1:26 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I suppose you just can't insert into a view created like that. Why don't you just use a custom UserType and handle the trimming on the java side?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 1:27 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
According to me, the safest and easiest way to handle this situation is to use a custom type that would trim your string...

Have a look at http://forum.hibernate.org/viewtopic.php?t=925916&highlight=trim


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 1:28 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
Ooops, sorry gloeglm - we were posting at the same time ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 1:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
No Problem, better twice the same answer than no answer ;) PS: Nice to see another one reach the 100 posts - keep up posting :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 1:31 pm 
Newbie

Joined: Thu Jan 29, 2004 5:27 pm
Posts: 5
I can wire in an Interceptor to do all the trimming for me, but that
still doesn't help me.

When I do queries with prepared statement, they query parameters
have to be paddes as well.

The funny thing is If I don't use a prepared statement, but just
execute the sql string with a Statement the stuff that I'm querying
doesnt have to be padded with spaces.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 1:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Well you can have the userType trim the string before setting it in your objects, and have it fill up to a certain length before inserting into a query. Take a look at a simple type like net.sf.hibernate.type.StringType or some UserType examples in the forum and on the website. I am pretty sure this will solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 1:42 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
(Arrghhh - you have been faster again - force me to rewrite my post ;-)

I agree with gloeglm's approach. A few extra words however:

* For the queries, why not using a LIKE comparaison instead of a strict equal ?

* Otherwise, the padding approach is what I was busy writing before I saw gloeglm's post... Two remarks:

- the length of the field (for the padding) could be obtained from Hibernate's meta info;
- when querying, you can assign your parameters by forcing the type to your custom type. This way your value would be padded with blanks and an exact match *may* work.

(have never tried this approach however ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 1:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Quote:
the length of the field (for the padding) could be obtained from Hibernate's meta info


That would be really sweet ... I don't think however there is a nice API for this, or do you know a easy way?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 6:34 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
gloeglm wrote:
Quote:
the length of the field (for the padding) could be obtained from Hibernate's meta info


That would be really sweet ... I don't think however there is a nice API for this, or do you know a easy way?


I had a look and unfortunately, the Hibernate metadata do not contain the field length (only its type).
Anyway, so far Hibernate creates a new instance every time a UserType is used in the mapping file - so you have one instance per field.
The field length could be obtained from the JDBC PrepareStatement or Resultset the first time the UserType is used.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 6:40 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
The metadata available via Configuration includes length information.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.