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