-->
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.  [ 6 posts ] 
Author Message
 Post subject: mapping problems with Oracle char types after where clause
PostPosted: Thu Aug 25, 2005 1:52 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
2.1.8
Mapping documents:
<property
name="servername"
type="dars.apis.common.dao.hibernate.type.OracleCHAR"
column="servername"
length="10"
>
<meta attribute="property-type">java.lang.String</meta>
</property>
Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:
Oracle 9i
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:
for case 1 where it is supposed to be mapped
25 Aug 2005 13:50:35 : [DEBUG] net.sf.hibernate.SQL - select jobqueueli0_.instidq as instidq, jobqueueli0_.instid as instid, jobqueueli0_.instcd as instcd, jobqueueli0_.jobid as jobid, jobqueueli0_.userid as userid, jobqueueli0_.status as status, jobqueueli0_.priority as priority, jobqueueli0_.startdate as startdate, jobqueueli0_.starttime as starttime, jobqueueli0_.external_eval as externa10_, jobqueueli0_.read_sysin as read_sysin, jobqueueli0_.servername as servername, jobqueueli0_.last_mod_user as last_mo13_, jobqueueli0_.last_mod_date as last_mo14_ from job_queue_list jobqueueli0_ where (jobqueueli0_.status=? )and(jobqueueli0_.servername=? )and((jobqueueli0_.startdate<=? )or(jobqueueli0_.startdate is null ))and((jobqueueli0_.starttime<=? )or(jobqueueli0_.starttime is null )) order by jobqueueli0_.priority , jobqueueli0_.jobid
25 Aug 2005 13:50:35 : [DEBUG] net.sf.hibernate.impl.BatcherImpl - preparing statement
25 Aug 2005 13:50:35 : [DEBUG] net.sf.hibernate.type.StringType - binding '2005/02/11' to parameter: 3
25 Aug 2005 13:50:35 : [DEBUG] net.sf.hibernate.type.StringType - binding 'dars1' to parameter: 2
25 Aug 2005 13:50:35 : [DEBUG] net.sf.hibernate.type.StringType - binding '14:28' to parameter: 4
25 Aug 2005 13:50:35 : [DEBUG] net.sf.hibernate.type.StringType - binding 'D' to parameter: 1
25 Aug 2005 13:50:35 : [DEBUG] net.sf.hibernate.loader.Loader - processing result set
25 Aug 2005 13:50:35 : [DEBUG] net.sf.hibernate.loader.Loader - done processing result set (0 rows)
--------------------------------------------------------

for case 2 where I have 'dars1' hardcoded into the hql statement
25 Aug 2005 13:37:34 : [DEBUG] net.sf.hibernate.SQL - select jobqueueli0_.instidq as instidq, jobqueueli0_.instid as instid, jobqueueli0_.instcd as instcd, jobqueueli0_.jobid as jobid, jobqueueli0_.userid as userid, jobqueueli0_.status as status, jobqueueli0_.priority as priority, jobqueueli0_.startdate as startdate, jobqueueli0_.starttime as starttime, jobqueueli0_.external_eval as externa10_, jobqueueli0_.read_sysin as read_sysin, jobqueueli0_.servername as servername, jobqueueli0_.last_mod_user as last_mo13_, jobqueueli0_.last_mod_date as last_mo14_ from job_queue_list jobqueueli0_ where (jobqueueli0_.status=? )and(jobqueueli0_.servername='dars1' )and((jobqueueli0_.startdate<=? )or(jobqueueli0_.startdate is null ))and((jobqueueli0_.starttime<=? )or(jobqueueli0_.starttime is null )) order by jobqueueli0_.priority , jobqueueli0_.jobid
25 Aug 2005 13:37:34 : [DEBUG] net.sf.hibernate.impl.BatcherImpl - preparing statement
25 Aug 2005 13:37:34 : [DEBUG] net.sf.hibernate.type.StringType - binding '2005/02/11' to parameter: 2
25 Aug 2005 13:37:34 : [DEBUG] net.sf.hibernate.type.StringType - binding '14:28' to parameter: 3
25 Aug 2005 13:37:34 : [DEBUG] net.sf.hibernate.type.StringType - binding 'D' to parameter: 1
25 Aug 2005 13:37:34 : [DEBUG] net.sf.hibernate.loader.Loader - processing result set
--------------------------------------------------------------

The following code does not return values when it should
Code:
"from JobQueueList jql where jql.status=:status and jql.servername=:servername "
                                + " and (jql.startdate <=:startdate or jql.startdate is null) "
                                + " and (jql.starttime <=:starttime or jql.starttime is null) "
                                + " order by jql.priority, jql.comp_id.jobid",
                        jobQueueList);

The problem is isolated to servername. In my test, I have
Code:
setServername("dars1");

However, if I make the test line
Code:
setServerName("dars1     ")
it does work.

The following code also returns values
Code:
"from JobQueueList jql where jql.status=:status and jql.servername='dars1' "
                                + " and (jql.startdate <=:startdate or jql.startdate is null) "
                                + " and (jql.starttime <=:starttime or jql.starttime is null) "
                                + " order by jql.priority, jql.comp_id.jobid",
                        jobQueueList);

as you can see, I've hardcoded the value into the statement.

servername is defined as type CHAR(10). I cannot change it to varchar, nvarchar, varchar2 or whatever, it is a legacy database.

I've tried implementing this UserDefinedType at the bottom of this http://www.hibernate.org/90.html web page, but it appears that nullSafeGet and nullSafeSet do not get used on mapping parameters that are after the where clause.

Please help, I've spent days trying to figure this out.

chris


Top
 Profile  
 
 Post subject: simplest approach
PostPosted: Thu Aug 25, 2005 3:00 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
well, ORACLE adds spaces to the end and compares the padded values, therefore 'xx ' works when 'xx' returns nothing.

Simplest thing you can do is to set parameters like this setServerName( org.apache.commons.lang.StringUtils(rightPad(v,10,' ' ));

But it is better perhaps to implement that solution you already tried http://www.hibernate.org/90.html

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 3:28 pm 
Newbie

Joined: Mon Jul 18, 2005 7:45 pm
Posts: 15
Location: Argentina
Can you try with Hibernate 3.0.5?
I had the same problem and I resolved using a Char User Type and calling

st.setObject(index,(String)value,OracleTypes.FIXED_CHAR);

at nullSetSafe method.

I also have to filter for this field at the where clause and everything works fine.

Daniel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 3:41 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
dardison wrote:
I also have to filter for this field at the where clause and everything works fine.


Don't quite know what you mean by this sentence. I have tried that class on that link but I can't get it to work correctly. I am seeing that the only UDTs I can get those nullSafeGet/Set methods to run on are members of the primary key. I just don' know why it's not working, it appears as though it should. I must have my mapping file wrong but I don't know what it is supposed to be.

I can get around the problem by putting the rightPad statement in the setter method of a class that extends my POJO. I have to put it in the POJO and not when it is called because I am developing a set of APIs to access our database system that a suite of programs will be using and I need to make it simple for these different programs to use the APIs.

I guess I'll just go with the POJO padding for now because I can't get the good way to work.

I was also trying to delay the upgrade of our hibernate version to our next major release ;)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 4:17 pm 
Newbie

Joined: Mon Jul 18, 2005 7:45 pm
Posts: 15
Location: Argentina
Sorry about my english, but we use to speak spanish all the time :)

What I was trying to said is that the only difference between my code and your code as far as I can see is that I´m running with Hibernate 3.0.5
and for me the trick of using OracleTypes.FIXED_CHAR works fine in the where clause, so maybe the version is the problem.

regards,
Daniel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 4:41 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
ok. Thanks for your help. I will definitely give this a try when I finally decide to upgrade our hibernate version.

I used to study spanish in high school. I'll tell you what, your english is a lot better than my spanish. ;)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.