-->
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: Using CreateSQL to retrieve entity?
PostPosted: Sun Jan 24, 2010 6:12 pm 
Newbie

Joined: Fri Sep 25, 2009 8:36 am
Posts: 9
Ive got a couple of entities which are related to each other but are rarely needed and contain a large amount of data.

The objects are linked by a primary key, so lets say "company.id" and "group.company_id". Now the group entity does not contain a property called "CompanyID" mainly because its only used when inserting and then never changed afterwards, so i thought it would be redundant to have within the entity.

Now i need to be able to retrieve a list of groups based on the company_id, but as the property is not within the entity i cannot seem to do it via the criteria, and if i do the SQL manually it doesnt seem to map it properly and i cant find any examples, so i was wondering if anyone had any details on how to achieve this...


Top
 Profile  
 
 Post subject: Re: Using CreateSQL to retrieve entity?
PostPosted: Mon Jan 25, 2010 5:10 am 
Newbie

Joined: Mon Jan 25, 2010 3:25 am
Posts: 6
Hi,

You can try using sql queries like below
String companyId = 1000;
StringBuffer sqlQ = new StringBuffer();
List<Object[]> groupList= new ArrayList<Object[]>();
sqlQ ="Select group_id from group where company_id = ";
sqlQ.append(companyId);
SQLQuery sqlQuery = session.createSQLQuery(sqlQ.toString());
groupList= sqlQuery.list();
if (groupList!= null) {
final Iterator<Object[]> itrgroupList = groupList.iterator();
while (itrgroupList .hasNext()) {
final Object[] groupObj= (Object[]) itrgroupList.next();
system.out.println(groupObj[0]);
}

Cheers,
Sudhir


Top
 Profile  
 
 Post subject: Re: Using CreateSQL to retrieve entity?
PostPosted: Fri Feb 05, 2010 2:03 pm 
Newbie

Joined: Sat Dec 26, 2009 7:05 am
Posts: 8
your group entity doesn't have a Company entity reference, and not company_id property?
if it should never be updated but only inserted for new groups, you can use this feature:

<property name="HireDate" column="HIRE_DATE" not-null="true" insert="true" update="false"/>
setting the property as insertable but not updateable

in my opinion you should always avoid drifting to corner cases, because they are less tested, and even if working good, it might be confusing understanding how to use them properly
but having the property and setting it to be not updateable seems very reasonable


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.