-->
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.  [ 11 posts ] 
Author Message
 Post subject: when to use HQL, when to use createCriteria? Pros & Cons
PostPosted: Fri Aug 19, 2005 6:01 pm 
Newbie

Joined: Tue Aug 16, 2005 2:20 am
Posts: 19
Location: California, USA
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

Hi,

I wrote couple of queries using HQL, seems to me very powerful and good enough. Why people using createCriteria. I am just afraid I would miss something good of hibernate. Pros and Cons between these two?

thanks,

xiuping


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 7:17 pm 
Beginner
Beginner

Joined: Thu Feb 17, 2005 9:20 pm
Posts: 36
Location: Vancouver, WA
They are both good. I would say it is up to your preferences. Criteria API works well in different kind of generic criteria builders. Because it is hierarchical by nature. Actualy, HQL builders can be built as well almost with the same effort. HQL is good when you have to create something more or less sophisticated and it is more clear to do with it, or something very specific to get better performance or just because it is easier to use for particular case. We desided to go with Criteria API in our app. It is more suitable for our needs vs. HQL. We have quite a few HQLs and propably we will convert them to Criteria later.

_________________
Vasyl Zhabko


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 8:27 pm 
Newbie

Joined: Tue Aug 16, 2005 2:20 am
Posts: 19
Location: California, USA
thank you very much for your kindly reply.

I will convert my HQL into createCriteria just to feel the difference.

BTW, once I put my description of the table information inside hbm.xml,
there should be a tool to be able to create the corresponding Java Object Class, right ?

Right now I manually wrote couple of getters and setters, it works. But I feel like hibernate should have tool to generate java class automatically , right? otherwise, why we need to specifiy inside hbm.xml?

sorry for my silly questions, I just started to learn hibernate. it is pretty cool.

regards,

xiuping


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 9:14 pm 
Newbie

Joined: Mon Aug 15, 2005 7:53 pm
Posts: 8
Location: Córdoba, Argentina
xyang, you have some tools to create java source from your hbm.xml
and, you have tools to create hbm.xml AND .java

you should try some eclipse plugins like Hibernate Synchronizer, MyEclipse, and Middlegen.
Hibernate tools includes hbm2java, an ant task that lets you do what you're looking for.

So, you can generate all of your hbm.xml, .java, and even hibernate.config.xml. You would just modify those files for fine tuning, if needed.

Greetings
Matías


Top
 Profile  
 
 Post subject: need some help
PostPosted: Mon Aug 22, 2005 2:13 pm 
Newbie

Joined: Tue Aug 16, 2005 2:20 am
Posts: 19
Location: California, USA
thanks a lot for your advice.

I have found the Hibernate Synchronzier and downloaded and unzipped. I manually added those jar files into Eclipse Project property build path.

However, after that, from "File-New-Other" , I am not able to see "Hibernate", which means somehow my newly installed Hibernate Synchronizer didn't get hooked up with Eclipse.

I feel kind of stupid, spend an hour still no clue. Any one can help?

thanks a lot

xiuping


Top
 Profile  
 
 Post subject: let me explain it more clearly
PostPosted: Mon Aug 22, 2005 4:17 pm 
Newbie

Joined: Tue Aug 16, 2005 2:20 am
Posts: 19
Location: California, USA
in fact, what I want to know is :

inside Eclipse 3.0, how can I make the newly installed "Hibernate Synchronizer" appears under "File -->New --->Other --->Hibernate",
right now, I can not see "hibernate" under "Other". But I do see other
stuff under "Other", I wonder how those items were made visible under "Other". I guess I need to do the similiar thing, but don't know how.

Anyone knows?

thanks,

xiuping


Top
 Profile  
 
 Post subject: Hibernate Synchronizer
PostPosted: Mon Aug 22, 2005 6:38 pm 
Newbie

Joined: Mon Aug 15, 2005 7:53 pm
Posts: 8
Location: Córdoba, Argentina
xyang, once you downloaded the plugin, you have to unzip the "plugins" folder inside the zip to the eclipse folder (you'll see that there's a "plugins" folder inside the eclipse folder). Than, restart eclipse and that's all.
You don't have to include the jars in the classpath.

Regards,
Matías


Top
 Profile  
 
 Post subject: I figured out the installation, and now more question
PostPosted: Mon Aug 22, 2005 7:42 pm 
Newbie

Joined: Tue Aug 16, 2005 2:20 am
Posts: 19
Location: California, USA
hi,

I figured out the installation, instead of unzip, I need to use "update site", that made Hibernate Synchronizer a plugin.

I also figured out how to use DB connection and refresh tables and create the .hbm file.

Seems to me it is hard to use this tool. Spent the whole afternoon.

Now I am trying to create the Java Object file based on the .hbm file, and I don't know how. ( Have not figured out yet).

Thanks for your reply.

xiuping


Top
 Profile  
 
 Post subject: okay, I figured it out how to generate java object now
PostPosted: Mon Aug 22, 2005 8:03 pm 
Newbie

Joined: Tue Aug 16, 2005 2:20 am
Posts: 19
Location: California, USA
But it is so hard to use.

It generated bunch of other java classes which I don't need them. I am not sure if I am doing the right thing.


Top
 Profile  
 
 Post subject: Hb Sync
PostPosted: Mon Aug 22, 2005 9:39 pm 
Newbie

Joined: Mon Aug 15, 2005 7:53 pm
Posts: 8
Location: Córdoba, Argentina
I really can't remember too much about Hibernate Sync, I haven't used it for a while. But I guess you're talking about de DAOs it generates.
HB Sync generates first de hbm.xml, then you right click on those files and chose Synchronize and it generates the java files.
Along with the POJOs, Data Access Objects are generated, so you can use them to retrieve, save, update and delete objects from the database. Take a look at those classes to find out exactly what they do.
It also generates a Base class for every POJO... that base class you should never modify, as it's synchronized and regenerated when you make some changes to the database. You should modify the POJO that inherits the base class.

I hope you understand me... ask for help again if my explanation is not clear enough.

You should also refer to Hybernate Synchronizer docs for further help


Top
 Profile  
 
 Post subject: thanks.
PostPosted: Tue Aug 23, 2005 1:16 pm 
Newbie

Joined: Tue Aug 16, 2005 2:20 am
Posts: 19
Location: California, USA
This hibernate synchronizer is not very good, it generates too much stuff, not clean. Since I am using Spring framework for transactions, I don't need those being generated.

Anyone knows that if hibernate itself provide a better tool to generate POJO source? I read the hibernate manual document, it mentioned there is a "Development Wizard", where can I get this "Wizard"?

thanks a lot,

xiuping


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