-->
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.  [ 1 post ] 
Author Message
 Post subject: return-join and composite elements in native sql
PostPosted: Sun Oct 22, 2006 12:02 pm 
Newbie

Joined: Sun Oct 22, 2006 11:28 am
Posts: 15
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

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:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html

Hi All,

I cannot find a solution to the following problem using Hibernate 3.2.0ga:


I have a class with a set of composite-elements like this:

<set name="messageTranslations"
lazy="true"
table="message_body_translation">
<key column="message_id" />

<composite-element class="MessageTranslation" >
<property name="body" column="body" not-null="true" />
<property name="subject" column="subject" not-null="true" />
<many-to-one name="language" class="Language" column="language_id" not-null="true" />
</composite-element>
</set>


Here is my query:

<sql-query name="all.messages.for.specific.user">

<return alias="message" class="Message" />

<return-join alias="mc" property="message.messageCategory" />
<return-join alias="mi" property="message.messageImportance" />

<return-join alias="messageTranslations" property="message.messageTranslations"/>

<!--
<return-join alias="mru" role="message.readByUsers"/>
<return-join alias="mrl" role="message.readByLocations"/>
-->

select distinct {message.*},
{mc.*},
{mi.*},
{messageTranslations.*},
{mru.*},
{mrl.*}
from
user u inner join user_location_link ull on u.id = ull.user_id,
user u2 inner join user_brand_link ubl on u2.id = ubl.user_id,
user u3 inner join user_role_link url on u3.id = url.user_id,
location l inner join message_addressing_location mal on l.id = mal.location_id,
brand b inner join message_addressing_brand mab on b.id = mab.brand_id,
role r inner join message_addressing_role mar on r.id = mar.role_id,
user u4 inner join message_addressing_user mau on u4.id = mau.user_id,
message message left outer join message_body_translation messageTranslations on message.id=messageTranslations.message_id
left outer join message_category mc on message.message_category_id=mc.id
left outer join message_importance mi on message.message_importance_id=mi.id
left outer join message_read_user mru on message.id=mru.message_id
left outer join message_read_location mrl on message.id=mrl.message_id
where ( u.id = :username and u.id=u2.id=u3.id ) and
u4.default_language_id = messageTranslations.language_id and
( l.code = :location and l.brand_id = b.id and ull.location_id in ( mal.location_id ) ) and
( message.id = mal.message_id or
message.id = mab.message_id or
( message.id = mar.message_id and url.role_id in ( mar.role_id ) ) or
( message.id = mau.message_id and u4.id = mau.user_id ) )
</sql-query>

The problem occurs on the <return-join alias="messageTranslations" property="message.messageTranslations"/>
line.

Hibernate generates an NPE as follows:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [hibernate-mysql-session-factory.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException

Caused by:

java.lang.NullPointerException

at org.hibernate.loader.custom.sql.SQLQueryParser.resolveProperties(SQLQueryParser.java:182)

at org.hibernate.loader.custom.sql.SQLQueryParser.resolveCollectionProperties(SQLQueryParser.java:135)

at org.hibernate.loader.custom.sql.SQLQueryParser.substituteBrackets(SQLQueryParser.java:98)

at org.hibernate.loader.custom.sql.SQLQueryParser.process(SQLQueryParser.java:51)

at org.hibernate.loader.custom.sql.SQLCustomQuery.<init>(SQLCustomQuery.java:110)

at org.hibernate.engine.query.NativeSQLQueryPlan.<init>(NativeSQLQueryPlan.java:43)

at org.hibernate.engine.query.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:114)

at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:444)

at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:351)

at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1218)


I have looked at the tests buy none show retrieving a collection of composite elements using native sql.

I have also tried load-collection which also generates the same error. Is this a bug or do I have to do something different in my sql-query element?

Thanks in advance,
Ian


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.