-->
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: getting a single row from hibernate
PostPosted: Wed Feb 15, 2006 12:16 pm 
Newbie

Joined: Wed Feb 01, 2006 10:33 am
Posts: 15
Hey

I am having problems getting a single row and setting it to a object.

I get no results with this query

Code:
Module module = (Module)session.createQuery("from Module mod where mod.moduleID = 1");


The table looks like this:
Code:
[b]module[/b]
moduleid: INTEGER
modulename:VARCHAR
description: VARCHAR
path : VARCHAR



moduleID is a Integer not an int

does anybody have a solution?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 15, 2006 12:30 pm 
Beginner
Beginner

Joined: Wed Feb 08, 2006 5:45 pm
Posts: 23
Location: Phoenix, AZ
You're not getting back a Module from that method call. If you look at the JavaDoc APIs you'll notice that session.createQuery( String query ) returns a Query Object (I'm surprised you're not getting a ClassCastException). If you look at the Query JavaDoc you can use a few things to get a result:

.list() will return the results in a list (or an empty list if no results found)

.uniqueResult() will return a single instance (or a exception if more than one is found or null if none is found)

.iterate() will return the results as an iterator

For example:
Code:
Module module = (Module)session.createQuery("from Module mod where mod.moduleID = 1").uniqueResult();


Hope this helps,
B

____________________________________
Please rate me if you found my post useful.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 15, 2006 12:41 pm 
Newbie

Joined: Wed Feb 01, 2006 10:33 am
Posts: 15
Yes that was all I needed. Thank you.

I was stupid when assuming removing the .list() would only give me one result.

I will try reading the API next time :)


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.