-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate query help
PostPosted: Wed Sep 20, 2006 3:45 am 
Newbie

Joined: Wed Sep 06, 2006 8:00 am
Posts: 2
Hi I need a help on Hibernate Query
I have class Task which contains List of NEs ,the relation between these two classes is one-many,so I have created two tables named as task and ne.
the structure of task table looks like this
Table name task
id key time type and structure of ne table is
id name displayname fk.

now i want to select list of tasks based on key(Task) and name(NE)..here my problem is how to write the query based on list values,if iam writing like this its throwing an error


session.createQuery("from import Task st where st.key=:val and st.NE.name=:name")
.setString("val",pk)
.setString("name",name)
.list();


Top
 Profile  
 
 Post subject: Joins and Normalization
PostPosted: Wed Sep 20, 2006 8:14 am 
Newbie

Joined: Tue Sep 12, 2006 7:03 am
Posts: 7
Location: Berlin
Hi Subba,

I'm not sure if I understood all aspects of your question. You might want to describe your table structure more clearly and apply normalization rules to your columns.

I'll give this a try by means of MySql DDL:

create table TASK (
TASK_ID int primary key,
TIME timestamp,
TYPE int);

create table NE(
NE_ID int primary key,
NAME varchar(40),
DISPLAYNAME varchar(60),
TASK_ID int);

Given these column names, it becomes clear that NE.TASK_ID is a foreign key referencing table TASK. That is what is meant by proper normalization. Column names like NAME or TIME should be avoided, though.

It then appears to me you are missing some sort of join in your hql. Say you had two pojo classes Task and Ne, with Task.nes being a Set of Ne, a join might look like this:

session.createQuery("from Task as tsk inner join tsk.nes as ne where tsk.taskId=:key and ne.name=:name");

Note that list elements returned by this query will be arrays of Objects.

Hope this helps
Fritz


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