-->
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.  [ 9 posts ] 
Author Message
 Post subject: working with mssql, db2, but not with oracle
PostPosted: Fri Aug 19, 2005 2:28 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:

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:

I believe hibernate is generating invalid sql for my oracle database select statements. My unit tests work fine against a mssql and db2 database but this select statement returns no rows when it should return 32. Hand writing this select statement in a sql editor for oracle also returns the correct number of results.

Code:
getHibernateTemplate()
                .findByValueBean(
                        "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);


if I delete the jql.servername=:servername this query returns values, or even if I hardcode it to be jql.servername='somevalue' it works correctly.

snippets of the hbm file
Code:
...
<class
    name="dars.apis.audit.JobQueueList"
    table="job_queue_list"
>
    <meta attribute="generated-class" inherit="false">dars.apis.audit.BaseJobQueueList</meta>
   
    <composite-id name="comp_id" class="dars.apis.audit.JobQueueListPK">
        <meta attribute="generated-class" inherit="false">dars.apis.audit.BaseJobQueueListPK</meta>
   
        <key-property
            name="instidq"
            column="instidq"
            type="dars.apis.common.dao.hibernate.type.RightTrimmedStringUserType2"
            length="2"
        >
            <meta attribute="property-type">java.lang.String</meta>
        </key-property>
        <key-property
            name="instid"
            column="instid"
            type="dars.apis.common.dao.hibernate.type.RightTrimmedStringUserType8"
            length="8"
        >
            <meta attribute="property-type">java.lang.String</meta>
        </key-property>
...


    <property
        name="servername"
        type="dars.apis.common.dao.hibernate.type.RightTrimmedStringUserType10"
        column="servername"
        length="10"
    >
        <meta attribute="property-type">java.lang.String</meta>
    </property>
    <property
        name="status"
        type="java.lang.String"
        column="status"
        length="1"
    >
        <meta attribute="use-in-equals">true</meta>
    </property>
...


snippets of the calling test
Code:
...
JobQueueList jql = new JobQueueList();
        jql.setStatus("D");
        jql.setServername("dars1");
        jql.setStartdate("2005/02/11");
        jql.setStarttime("14:28");

        List requestsToProcess = dao.findRequestsToProcess(jql);
...


snippets of JobQueueList object

Code:
    /** nullable persistent field */
    private String servername;
...
    public void setServername(String servername) {
        this.servername = servername;
    }


    public String getServername() {
        return this.servername;
    }
...


the data for the database is populated by dbunit, the hbm files generated by middlegen (run against the mssql server)

any help would be greatly appreciated


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 2:42 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
oh right, the sql


Hibernate: 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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 3:25 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
.. and error and log are ...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 3:36 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
-net.sf.hibernate.hql.QueryTranslator - HQL: from dars.apis.audit.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

-net.sf.hibernate.hql.QueryTranslator - 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
net.sf.hibernate.impl.BatcherImpl - about to open: 0 open PreparedStatements, 0 open ResultSets
org.springframework.jdbc.datasource.DriverManagerDataSource - Creating new JDBC connection to [jdbc:oracle:thin:@MYDATABASE]

-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

-net.sf.hibernate.impl.BatcherImpl - preparing statement
-net.sf.hibernate.type.StringType - binding '2005/02/11' to parameter: 3
-net.sf.hibernate.type.StringType - binding 'dars1' to parameter: 2
-net.sf.hibernate.type.StringType - binding '14:28' to parameter: 4
-net.sf.hibernate.type.StringType - binding 'D' to parameter: 1
-net.sf.hibernate.loader.Loader - processing result set
-net.sf.hibernate.loader.Loader - done processing result set (0 rows)
-net.sf.hibernate.impl.BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets
-net.sf.hibernate.impl.BatcherImpl - closing statement
-net.sf.hibernate.loader.Loader - total objects hydrated: 0
-net.sf.hibernate.impl.SessionImpl - initializing non-lazy collections
-org.springframework.orm.hibernate.HibernateTemplate - Eagerly flushing Hibernate session
-net.sf.hibernate.impl.SessionImpl - flushing session
-net.sf.hibernate.impl.SessionImpl - Flushing entities and processing referenced collections
-net.sf.hibernate.impl.SessionImpl - Processing unreferenced collections
-net.sf.hibernate.impl.SessionImpl - Scheduling collection removes/(re)creates/updates
-net.sf.hibernate.impl.SessionImpl - Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
-net.sf.hibernate.impl.SessionImpl - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
-net.sf.hibernate.impl.SessionImpl - executing flush
-net.sf.hibernate.impl.SessionImpl - post flush
-org.springframework.orm.hibernate.SessionFactoryUtils - Closing Hibernate session
-net.sf.hibernate.impl.SessionImpl - closing session
-net.sf.hibernate.impl.SessionImpl - disconnecting session


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 4:40 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
is servername define like CHAR in database ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 4:45 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
Name Null? Type
----------------------------------------- -------- ----------------------------
INSTIDQ NOT NULL CHAR(2)
INSTID NOT NULL CHAR(8)
INSTCD NOT NULL CHAR(3)
JOBID NOT NULL CHAR(16)
USERID NOT NULL CHAR(30)
STATUS CHAR(1)
PRIORITY NUMBER(38)
STARTDATE CHAR(10)
STARTTIME CHAR(5)
EXTERNAL_EVAL CHAR(1)
READ_SYSIN CHAR(1)
SERVERNAME CHAR(10)
LAST_MOD_USER VARCHAR2(30)
LAST_MOD_DATE DATE


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 4:58 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
CHAR in oracle have padded blank chars (length is always 10)
for example, if you save 'dars1', oracle add blank and in column is 'dars1 ' (5 blanks)

try this from sqlplus

select servername,length(servername)
from <your_table_name>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 5:17 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
YAY!! Thanks for the help. You have been given one credit.

Yeah, as you can see we did try to remedy that problem with our RightTrimmedStringUserType10 class... but it is malfunctioning because we tried to update the hibernate jar file to the newest version (but turns out we're going to do that later so we went back to 2.1.8) and somehow our stuff got broken.

I ended up doing
Code:
JobQueueList jql = new JobQueueList();
        jql.setStatus("D");
        jql.setServername("dars1     ");
        jql.setStartdate("2005/02/11");
        jql.setStarttime("14:28");

(adding 5 spaces after the dars1)

to get the query to work, so now I know what to fix.

Thanks again


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 5:25 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
don't use char (if you can) - use varchar2 or nvarchar2


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