-->
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.  [ 6 posts ] 
Author Message
 Post subject: load object without primary key and HQL
PostPosted: Tue May 03, 2005 12:15 pm 
Newbie

Joined: Fri Mar 18, 2005 1:05 pm
Posts: 8
Location: Delhi
I am using hibernate 3 version.

I want to load the object without passing the ID.
I dont want to use HQL.

What I want is .....suppose i have class employee with few records in it.
and I want all the records from this class

now the question can this be done without using HQL.

If yes how ?

Secondly I also want to know If I am loading the class can I load it without passing the primary key.
Can I load it by passing some other attribute of class.

Pls suggest I am in deep trouble .....

:(

Thanks in advance


Top
 Profile  
 
 Post subject: Re: load object without primary key and HQL
PostPosted: Tue May 03, 2005 12:57 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
sunilkumarsh wrote:
I am using hibernate 3 version.

I want to load the object without passing the ID.
I dont want to use HQL.

What I want is .....suppose i have class employee with few records in it.
and I want all the records from this class

now the question can this be done without using HQL.

If yes how ?

Secondly I also want to know If I am loading the class can I load it without passing the primary key.
Can I load it by passing some other attribute of class.

Pls suggest I am in deep trouble .....

:(

Thanks in advance


You can return all Employee objects using session.createCriteria(Employee.class).list();

You can only execute the session.load() method using the PK but there are many other ways to get your data loaded, including using Criteria and Query objects. Both allow you to specifiy properties other than the primary key.

Check out the docs... there are many examples.


Top
 Profile  
 
 Post subject: HQL or Object traversing?????
PostPosted: Wed May 04, 2005 6:32 am 
Newbie

Joined: Fri Mar 18, 2005 1:05 pm
Posts: 8
Location: Delhi
Thanks a lot for answering my earlier question.
I tried it and its working.....

It will be nice of u ...
if u could make one more thing clear to me ....

Is it oky to use HQL?
If yes which situation should we use it ?

or we should always try and fetch objects using traversing ?

which of the 2 ways is efficient ?
whats the advantage of using either of them ?


Top
 Profile  
 
 Post subject: Re: HQL or Object traversing?????
PostPosted: Wed May 04, 2005 9:28 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
sunilkumarsh wrote:
Thanks a lot for answering my earlier question.
I tried it and its working.....

It will be nice of u ...
if u could make one more thing clear to me ....

Is it oky to use HQL?
If yes which situation should we use it ?

or we should always try and fetch objects using traversing ?

which of the 2 ways is efficient ?
whats the advantage of using either of them ?


In a majority of cases, you shouldn't need to use HQL but there are definitely cases where it comes in handy.

Check out section 14 Tips and Tricks of the documentation. I use HQL to check if a certain data exists in the database without having to return the data
Code:
select count(*) from Employee emp where emp.lastName = :lastName and emp.firstName = :firstName


Also anytime I need to use a subselect for example:
Code:
from MyObject myo where myo.dateCollected =
          (select max(myo2.dateCollected)
             from MyObject myo2 where myo2.id = myo.id)


Top
 Profile  
 
 Post subject: Re: HQL or Object traversing?????
PostPosted: Wed May 04, 2005 9:29 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
I should note that I haven't worked with all of the new features that Hibernate 3 has added so there may be even fewer reasons to use HQL, but I wouldn't be afraid to use it. It's in the product for a reason.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 3:53 pm 
Beginner
Beginner

Joined: Wed Oct 29, 2003 10:43 am
Posts: 38
Location: Chicago
The reason why I am attempting to use HQL is that our compnies product runs against Oracle or mssql server.

The language is basically sql but there are some differences.
I am hoping to use HQL to resolve the differences so that I dont have to write
2 different sets of querys.

Just a thought

_________________
LET IT BE :)


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