-->
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.  [ 5 posts ] 
Author Message
 Post subject: creating multiple dynamic obje
PostPosted: Wed Dec 01, 2004 10:17 pm 
Newbie

Joined: Wed Dec 01, 2004 12:13 am
Posts: 4
Hibernate version: 2.1.6

multiple dynamic object instantiation is it possible?

Is it possible to write query like the following?

select new User(u.Id, u.FirstName), new Message(m.Id) from User u join u.Message m

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 02, 2004 10:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
no, not currently.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 02, 2004 12:00 pm 
Newbie

Joined: Wed Dec 01, 2004 12:13 am
Posts: 4
Is there any way I can add/patch quickly? The reason I am intersted is hibernate is making unecessary extra queries to retrieve associate objects. For example I have the following mapping

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

<hibernate-mapping>
<class name="fleetcycle.domain.framework.communication.MessageRecipient"
table="MESSAGE_RECIPIENT">
<id
column="MESSAGE_RECIPIENT_ID"
name="Id"
type="string"
>
<generator class="uuid.hex" />
</id>
<many-to-one
class="fleetcycle.domain.framework.communication.UserMessage"
name="UserMessage"
not-null="true"
outer-join="true"
>
<column name="USER_MESSAGE_ID" />
</many-to-one>
</class>
<class name="fleetcycle.domain.framework.communication.UserMessage"
table="USER_MESSAGE">
<id
column="USER_MESSAGE_ID"
name="Id"
type="string"
>
<generator class="uuid.hex" />
</id>
<many-to-one
class="fleetcycle.domain.framework.security.User"
name="senderUser"
not-null="true"
outer-join="true"
>
<column name="SENDER_USER_ID" />
</many-to-one>
<set inverse="true" name="MessageRecipientSet" lazy="true">
<key column="USER_MESSAGE_ID" />
<one-to-many class="fleetcycle.domain.framework.communication.MessageRecipient" />
</set>
</class>
</hibernate-mapping>


MessageRecipient has many-to-one relation with UserMessage. When I make query "from MessageRecipient" to retrieve all message recipient objects hibernate is not using join query. It's making individual queries to these 2 tables.

I have 4 entries in message_recipient table so i can see total 5 sql queries being made. One for retrieving data from message_recipient table and 4 queries for retreiving user_message.


Hibernate: select messagerec0_.MESSAGE_RECIPIENT_ID as MESSAGE_1_, messagerec0_.USER_MESSAGE_ID as USER_MES7_ from MESSAGE_RECIPIENT messagerec0_
Hibernate: select usermessag0_.USER_MESSAGE_ID as USER_MES1_2_, usermessag0_.SENDER_USER_ID as SENDER_U8_2_, user1_.USER_ID as USER_ID0_, user1_.LOGIN_ID as LOGIN_ID0_, from USER_MESSAGE usermessag0_ left outer join FC_USER user1_ on usermessag0_.SENDER_USER_ID=user1_.USER_ID where usermessag0_.USER_MESSAGE_ID=?
Hibernate: select usermessag0_.USER_MESSAGE_ID as USER_MES1_2_, usermessag0_.SENDER_USER_ID as SENDER_U8_2_, user1_.USER_ID as USER_ID0_, user1_.LOGIN_ID as LOGIN_ID0_, from USER_MESSAGE usermessag0_ left outer join FC_USER user1_ on usermessag0_.SENDER_USER_ID=user1_.USER_ID where usermessag0_.USER_MESSAGE_ID=?
Hibernate: select usermessag0_.USER_MESSAGE_ID as USER_MES1_2_, usermessag0_.SENDER_USER_ID as SENDER_U8_2_, user1_.USER_ID as USER_ID0_, user1_.LOGIN_ID as LOGIN_ID0_, from USER_MESSAGE usermessag0_ left outer join FC_USER user1_ on usermessag0_.SENDER_USER_ID=user1_.USER_ID where usermessag0_.USER_MESSAGE_ID=?
Hibernate: select usermessag0_.USER_MESSAGE_ID as USER_MES1_2_, usermessag0_.SENDER_USER_ID as SENDER_U8_2_, user1_.USER_ID as USER_ID0_, user1_.LOGIN_ID as LOGIN_ID0_, from USER_MESSAGE usermessag0_ left outer join FC_USER user1_ on usermessag0_.SENDER_USER_ID=user1_.USER_ID where usermessag0_.USER_MESSAGE_ID=?
Hibernate: select usermessag0_.USER_MESSAGE_ID as USER_MES1_2_, usermessag0_.SENDER_USER_ID as SENDER_U8_2_, user1_.USER_ID as USER_ID0_, user1_.LOGIN_ID as LOGIN_ID0_, from USER_MESSAGE usermessag0_ left outer join FC_USER user1_ on usermessag0_.SENDER_USER_ID=user1_.USER_ID where usermessag0_.USER_MESSAGE_ID=?


Is there any thing I miss in my mapping? or is it a desired hibernate behavior?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 02, 2004 12:49 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
use the "fetch" keyword


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 02, 2004 11:46 pm 
Regular
Regular

Joined: Fri Nov 12, 2004 12:07 am
Posts: 57
Location: Beijing,China
add lazy="true" in class in mapping files.


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