-->
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.  [ 8 posts ] 
Author Message
 Post subject: Query causing NPE
PostPosted: Wed Aug 10, 2005 1:11 pm 
Beginner
Beginner

Joined: Mon Jun 06, 2005 12:10 pm
Posts: 20
I'm using Hibernate 3.0.5 and am trying to run the following HQL query

Code:
select user.uid,user.password,user.authorities from UserBackingData as user where user.username = ?


This causes Hibernate to throw a NPE. I've tried with different combinations of joins but nothing seems to help except for taking the user.authorities select element out. I'm not sure what's going on, but I'm guessing it's my mapping. Any ideas?

Thanks,
Rich

PS. the mapping for UserDetails is below as is the full stack trace for the exception.

Code:
<hibernate-mapping>
    <class name="com.contentconnections.mpl.publisher.auth.UserBackingData" table="mpl_users">
        <id name="uid" column="uid" >
            <generator class="uuid" />
        </id>

        <natural-id mutable="true">
            <property name="username" />
        </natural-id>

        <property name="password" />

        <set name="authorities" table="mpl_authorities" lazy="true">
            <key column="uid" />
            <composite-element class="com.contentconnections.mpl.publisher.auth.MutableGrantedAuthority">
                <property name="authority" />
            </composite-element>
        </set>

        <one-to-one name="profile" lazy="false" />
    </class>
</hibernate-mapping>


Code:
java.lang.NullPointerException
        at org.hibernate.hql.ast.FromElementType.renderIdentifierSelect(FromElementType.java:139)
        at org.hibernate.hql.ast.FromElement.renderIdentifierSelect(FromElement.java:162)
        at org.hibernate.hql.ast.SelectClause.renderNonScalarIdentifiers(SelectClause.java:372)
        at org.hibernate.hql.ast.SelectClause.renderNonScalarSelects(SelectClause.java:350)
        at org.hibernate.hql.ast.SelectClause.initializeExplicitSelectClause(SelectClause.java:192)
        at org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:440)
        at org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:351)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.afterQuery(HqlSqlBaseWalker.java:126)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:471)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
        at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
        at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
        at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
        at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
        at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
        at org.hibernate.impl.SessionImpl.list(SessionImpl.java:834)
        at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
        at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:751)
        at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:312)
        at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:742)
        at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:738)
        at com.contentconnections.mpl.publisher.auth.AuthenticationManagementDaoHibernateImpl.loadUserByUsername(AuthenticationManagementDaoHibernateImpl.java:47)
        at com.contentconnections.mpl.publisher.auth.test.AuthenticationManagementDaoHibernateImplTest.testLoadUserByUsername(AuthenticationManagementDaoHibernateImplTest.java:41)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 1:15 pm 
Senior
Senior

Joined: Thu May 12, 2005 11:40 pm
Posts: 125
Location: Canada
select user
from UserBackingData user
left join fetch user.authorities
where user.username = :username

Query q = ...
UserBackingData user = (UserBackingData)q.uniqueResult();
System.out.println(user.getUid());
System.out.println(user.getPassword());
System.out.println(user.getAuthorities());

Try that.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 1:23 pm 
Beginner
Beginner

Joined: Mon Jun 06, 2005 12:10 pm
Posts: 20
I was sort of hoping to not have to load the full UserBackingData object, just those three attributes. I went ahead and used that simple work around, but I'd prefer to find out why what I tried caused a NPE. Seems like something that should work, but doesn't.

Rich


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 1:25 pm 
Regular
Regular

Joined: Thu Dec 02, 2004 7:11 am
Posts: 85
Looks like a bug to me. In source code of FromElementType you can see several checks for persister != null, but in this particular place such check is missed.

As workaround you can join collection and use ALIAS_TO_ENTITY_MAP transformer to get results.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 1:27 pm 
Beginner
Beginner

Joined: Mon Jun 06, 2005 12:10 pm
Posts: 20
Good I'm glad I'm not just going nuts. Been fighting it all morning and was beginning to think it was just me.

Thanks,
Rich


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 1:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
The problem is not a bug (though the NPE is unhelpful).

You simply aren't allowed to have a collection-valued property in the select clause.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 1:41 pm 
Beginner
Beginner

Joined: Mon Jun 06, 2005 12:10 pm
Posts: 20
So in the documentation, chapter 15.4. "The select clause", is this query not valid?

Code:
select mother, offspr, mate.name
from DomesticCat as mother
    inner join mother.mate as mate
    left outer join mother.kittens as offspr


I mean, I assume that mother.kittens is a collection.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 1:46 pm 
Regular
Regular

Joined: Thu Dec 02, 2004 7:11 am
Posts: 85
rwallace wrote:
So in the documentation, chapter 15.4. "The select clause", is this query not valid?

Code:
select mother, offspr, mate.name
from DomesticCat as mother
    inner join mother.mate as mate
    left outer join mother.kittens as offspr


I mean, I assume that mother.kittens is a collection.


I think this is different beast. It's unroll entire collection to different records. So, my suggestion of woraround may be wrong.


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