-->
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: newbie: unexpected query results with joined-subclass
PostPosted: Fri Jul 22, 2005 4:18 pm 
Newbie

Joined: Wed Jul 20, 2005 9:40 am
Posts: 11
Location: Augsburg
I am confused about the following behaviour:



Code:
return (Employee) s.createQuery("from Employee e where e.UID = :uid")
               .setLong("uid", new Long("1").longValue())
               .uniqueResult();


returns no results (null), but

Code:
return (Employee) s.createQuery("from Employee e where e.UID = 1")
               .uniqueResult();


returns the expected object.

Employee is a child of User and the mapping is "class per subclass"
mapping data:
Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class table="BENUTZER"
        name="girocom.share.model.User"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="UID"
            column="UID"
            type="java.lang.Long"
        >
            <generator class="native">
            </generator>
        </id>

        <property
            name="userName"
            type="java.lang.String"
            update="true"
            insert="true"
            column="userName"
        />

        <property
            name="rolleKey"
            type="java.lang.Integer"
            update="true"
            insert="true"
            column="rolleKey"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-User.xml
            containing the additional properties and place it in your merge dir.
        -->

        <joined-subclass table="MITARBEITER"
            name="girocom.share.model.Employee"
            dynamic-update="false"
            dynamic-insert="false"
        >
        <key
            column="UID"
        />
        <property
            name="kuerzel"
            type="java.lang.String"
            update="true"
            insert="true"
            column="kuerzel"
        />

      ...

        </joined-subclass>

    </class>

</hibernate-mapping>



parts of the log:
Code:
2005-07-22 21:04:43,500 DEBUG [org.hibernate.hql.ast.JoinProcessor] Using FROM fragment [MITARBEITER employee0_ inner join BENUTZER employee0_1_ on employee0_.UID=employee0_1_.UID]
2005-07-22 21:04:43,500 DEBUG [org.hibernate.hql.antlr.HqlSqlBaseWalker] query() >> end, level = 1
2005-07-22 21:04:43,500 DEBUG [org.hibernate.hql.ast.AST] --- SQL AST ---
\-[SELECT] QueryNode: 'SELECT'  querySpaces (MITARBEITER,BENUTZER)
    +-[SELECT_CLAUSE] SelectClause: '{derived select clause}'
    |  +-[SELECT_EXPR] SelectExpressionImpl: 'employee0_.UID as UID' {FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=e,role=null,tableName=MITARBEITER,tableAlias=employee0_,colums={,className=girocom.share.model.Employee}}}
    |  \-[SQL_TOKEN] SqlFragment: 'employee0_1_.userName as userName4_, employee0_1_.rolleKey as rolleKey4_, employee0_.kuerzel as kuerzel5_, employee0_.name as name5_'
    +-[FROM] FromClause: 'from' FromClause{level=1, fromElementCounter=1, fromElements=1, fromElementByClassAlias=[e], fromElementByTableAlias=[employee0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]}
    |  \-[FROM_FRAGMENT] FromElement: 'MITARBEITER employee0_ inner join BENUTZER employee0_1_ on employee0_.UID=employee0_1_.UID' FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=e,role=null,tableName=MITARBEITER,tableAlias=employee0_,colums={,className=girocom.share.model.Employee}}
    \-[WHERE] SqlNode: 'where'
       \-[EQ] SqlNode: '='
          +-[DOT] DotNode: 'employee0_.UID' {propertyName=UID,dereferenceType=4,propertyPath=UID,path=e.UID,tableAlias=employee0_,className=girocom.share.model.Employee,classAlias=e}
          |  +-[ALIAS_REF] IdentNode: 'employee0_.UID' {alias=e, className=girocom.share.model.Employee, tableAlias=employee0_}
          |  \-[IDENT] IdentNode: 'UID' {originalText=UID}
          \-[NAMED_PARAM] ParameterNode: '?'

2005-07-22 21:04:43,500 DEBUG [org.hibernate.hql.ast.ErrorCounter] throwQueryException() : no errors
2005-07-22 21:04:43,500 DEBUG [org.hibernate.hql.ast.QueryTranslatorImpl] HQL: from girocom.share.model.Employee e where e.UID = :uid
2005-07-22 21:04:43,500 DEBUG [org.hibernate.hql.ast.QueryTranslatorImpl] SQL: select employee0_.UID as UID, employee0_1_.userName as userName4_, employee0_1_.rolleKey as rolleKey4_, employee0_.kuerzel as kuerzel5_, employee0_.name as name5_ from MITARBEITER employee0_ inner join BENUTZER employee0_1_ on employee0_.UID=employee0_1_.UID where employee0_.UID=?
2005-07-22 21:04:43,500 DEBUG [org.hibernate.hql.ast.ErrorCounter] throwQueryException() : no errors
2005-07-22 21:04:43,500 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2005-07-22 21:04:43,500 DEBUG [org.hibernate.jdbc.ConnectionManager] opening JDBC connection
2005-07-22 21:04:43,500 DEBUG [org.hibernate.SQL] select employee0_.UID as UID, employee0_1_.userName as userName4_, employee0_1_.rolleKey as rolleKey4_, employee0_.kuerzel as kuerzel5_, employee0_.name as name5_ from MITARBEITER employee0_ inner join BENUTZER employee0_1_ on employee0_.UID=employee0_1_.UID where employee0_.UID=?
2005-07-22 21:04:43,500 INFO  [STDOUT] Hibernate: select employee0_.UID as UID, employee0_1_.userName as userName4_, employee0_1_.rolleKey as rolleKey4_, employee0_.kuerzel as kuerzel5_, employee0_.name as name5_ from MITARBEITER employee0_ inner join BENUTZER employee0_1_ on employee0_.UID=employee0_1_.UID where employee0_.UID=?
2005-07-22 21:04:43,500 DEBUG [org.hibernate.jdbc.AbstractBatcher] preparing statement
2005-07-22 21:04:43,500 DEBUG [org.hibernate.loader.hql.QueryLoader] bindNamedParameters() 1 -> uid [1]
2005-07-22 21:04:43,500 DEBUG [org.hibernate.type.LongType] binding '1' to parameter: 1
2005-07-22 21:04:43,500 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to open ResultSet (open ResultSets: 0, globally: 0)
2005-07-22 21:04:43,500 DEBUG [org.hibernate.loader.Loader] processing result set
2005-07-22 21:04:43,500 DEBUG [org.hibernate.loader.Loader] done processing result set (0 rows)
2005-07-22 21:04:43,500 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to close ResultSet (open ResultSets: 1, globally: 1)
2005-07-22 21:04:43,500 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2005-07-22 21:04:43,500 DEBUG [org.hibernate.jdbc.AbstractBatcher] closing statement


i get the expected result, when i execute the generated sql statement (the one in the log) on the console ('?' replaced by '1')

I am using jboss-4.0.2 and hibernate hibernate-3.1beta1
(first i tried: Hibernate-Version: 3.1.alpha1)

I hope somebody can help!
sincerely,
Christian


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 25, 2005 4:56 am 
Regular
Regular

Joined: Mon Jun 13, 2005 12:21 pm
Posts: 61
Location: Hannover
Hi tian,

as far as I can see you're queries should be ok. Which database do you use?
Have you checked you're database, if uid is a numeric datatype?
You can get some strange behavoiur depending on you're database when query string fields with long values.

Joerg


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 25, 2005 8:26 am 
Newbie

Joined: Wed Jul 20, 2005 9:40 am
Posts: 11
Location: Augsburg
I am using a MySql Database. The UID-Field is of type bigint(20). I am really worried about this!
Thanks for all your help!
Christian

Code:
USER
------
"Field","Type","Null","Key","Default","Extra"
"UID","bigint(20)","","PRI","","auto_increment"
"userName","varchar(255)","YES","","",""
"rolleKey","int(11)","YES","","",""

EMPLOYEE
------------
"Field","Type","Null","Key","Default","Extra"
"UID","bigint(20)","","PRI","0",""
"kuerzel","varchar(255)","YES","","",""
"name","varchar(255)","YES","","",""


Code:
USER-Contents
------------------
"UID","userName","rolleKey"
4,"",0
5,"",1
6,"",3
7,"",3

EMPLOYEE-Contents
-----------------------
"UID","kuerzel","name"
4,"AM","Armin Mayr"
5,"BU","Berta Ulrich"
6,"SR","Siegfried Roy"
7,"AB","Art Blakey"


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 25, 2005 9:14 am 
Newbie

Joined: Wed Jul 20, 2005 9:40 am
Posts: 11
Location: Augsburg
taking uid = 4 for the example above


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 26, 2005 7:11 pm 
Newbie

Joined: Wed Jul 20, 2005 9:40 am
Posts: 11
Location: Augsburg
With Integer as the datatype for uid it works correctly. maybe a bug?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 26, 2005 7:24 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Quote:
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">


Quote:
I am using jboss-4.0.2 and hibernate hibernate-3.1beta1
(first i tried: Hibernate-Version: 3.1.alpha1)


You DTD does not correspond to the version of Hibernate you are using.
Don't know, if this might be the reason for your problem.

Best regards
Sven


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 27, 2005 6:49 am 
Newbie

Joined: Wed Jul 20, 2005 9:40 am
Posts: 11
Location: Augsburg
It works! since i replaces the mysql-connector-3.1.8 with the mysql-connector-3.0.17).

thanks a lot for your help!!!


apropos:
after changing the hibernate dtd declaration to version 3.0 the deployment is a lot faster - the creation of the tables takes almost no time. Is this ok or is there something going wrong? I wouldnt complain :-)

best regards,
christian


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 27, 2005 11:20 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
tian wrote:
after changing the hibernate dtd declaration to version 3.0 the deployment is a lot faster - the creation of the tables takes almost no time. Is this ok or is there something going wrong? I wouldnt complain :-)


There is nothing going wrong.
If Hibernate is not able to locate the DTD you specified, it will of course take much more time.

Best regards
Sven


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 27, 2005 11:40 am 
Newbie

Joined: Wed Jul 20, 2005 9:40 am
Posts: 11
Location: Augsburg
:-)
Thanks again!!!
Christian


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.