-->
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.  [ 3 posts ] 
Author Message
 Post subject: Newbie with Named Query question
PostPosted: Mon Apr 23, 2007 11:50 am 
Newbie

Joined: Thu Feb 15, 2007 3:32 pm
Posts: 10
Hello - I have a situation where I have a POJO with 42 attributes however in one part of my application I only need to select 3 of these attributes. A co-worker suggested using a named query to select only the three fields I need. This works fine but an object array is returned with my data. I then need to update the data and then persists it. How do I associate the data returned in the object array to my POJO --> which in turn, is associated to the current session?



Code:
        List result = factory.getCurrentSession().getNamedQuery("com.west.mds.caselaw.DocumentFamily.expertInvertigatorFetch").setString("caseUuid", "I5443ba3071ab11d796fabc35f7796f7a").list();
        Object[] rs = (Object[]) result.get(0);


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 23, 2007 12:36 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Enabling dynamic-update for that entity will help trim down the update, but you're still going to select the whole thing when you load. I would strongly consider refactoring your model!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 24, 2007 2:25 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,
You are using a Report Query. ( select clause of HQL )
Report Query is used in read-only scenarios.
You can find more information in the book "Hibernate In Action"

>>> I then need to update the data and then persists it
It does not return entites and are never "dirty-checked". So, you cannot update the data and persist it.

You can have a look at these options,
i) normalize your table ( it is flattened now ) and have 1:1 mapping between entities which can then be loaded lazily.

ii) map more than 1 class to the same table with each of them having id column (primary key) and other interested columns. Use appropriate model ( dictated by columns required ) in your query.

-----------------------------------------------------------
Rate the reply if you find it helpful


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