-->
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.  [ 12 posts ] 
Author Message
 Post subject: Need help configuring Named Queries!!!
PostPosted: Mon Aug 04, 2008 6:24 pm 
Regular
Regular

Joined: Tue Jul 29, 2008 4:15 pm
Posts: 62
Location: Dallas, TX US
Hibernate version: hibernate-annotations 3.3.1, hibernate-commons-annotations 3.3.0.ga, hibernate-entitymanager3.3.2, hibernate-core 3.2

Name and version of the database you are using: Orcale XE 10g Release 2 (10.2)

I am using Hibernate Tools 3.2.2.Beta1 with Eclipse 3.3.2
---------------------------------------------------------------------------------------

I want to know how to do 2 things:

1. I want to add hibernate named queries to my hbm.xml files. Please understand that I am auto-generated these hbm.xml files from my reveng.xml file; I will call the hbm.xml file that was generated from the reveng.xml, "Classes.hbm.xml". Is there a way to use a second configuration file that only has the hibernate named queries defined in it. I will call this file: "NamedQueries.hbm.xml". So I would like to generated my POJOs based off of the NamedQueries.hbm.xml file and the Classes.hbm.xml file. Is this possible?

2. I want to be able to generate DAOs that only use Named Queries from Hibernate Tools. Is this possible?

Any advice is welcomed!

Thanks!

[/list]

_________________
pouncilt


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 05, 2008 4:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes should be possible.

Try and name the queries with the prefix of the classes entity names (by default their fully qualified class name) to make the dao generaiton pick them up.

and then just add that hbm.xml to your cfg.xml when you want to dao generate.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 05, 2008 1:18 pm 
Regular
Regular

Joined: Tue Jul 29, 2008 4:15 pm
Posts: 62
Location: Dallas, TX US
Its good to hear that this is possible.

How do I tell the dao generation to pick up this seperate file that has my named queries in it. For example, I would name my seperate file as "CommandQueries.hbm.xml" and it would look like so:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <query name="com.companyName.projectName.generated.valueobjects.CommandVO.retrieveByName">
        select command from CommandVO as command where command.name = ?
        <query-param name="commandName" type="string" />
    </query>

    <query name="com.companyName.projectName.generated.valueobjects.CommandVO.retrieveAll">
select command from CommandVO as command</query>
</hibernate-mapping>

Is this the correct syntax for the named query tags?

And some how I would tell the dao generation to pick up this file. Also the dao generation generates its own methods. I would want to replace these methods with my named query methods as defined in the CommandQueries.hbm.xml file. Is this possible?

Thanks!

_________________
pouncilt


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 05, 2008 2:27 pm 
Regular
Regular

Joined: Tue Jul 29, 2008 4:15 pm
Posts: 62
Location: Dallas, TX US
Okay, I figured it out I created the seperate file named CommandQueries.hbm.xml and through the Hibernate Configuration, via the Hibernate Tools plugin for Eclipse, I added the CommandQueries.hbm.xml mapping file to the Hibernate Configuration. And then I set up a new Hibernate Code Generation task and selected the dao exporter. I did not select the "Generate EJB3 annotations" checkbox, as it will not generate my named queries. The Hibernate Tools plugin for Eclipse is very NICE!

Now for the second part of my question:
The dao generation generates its own methods (persist(), attachDirty(), attachClean(), delete(), merge(), findById(), and findByExample()) . How can I replace these methods with my own named query methods as defined in the CommandQueries.hbm.xml file. Is this possible?

Lastly, I think I will have to use a custom reverse engineer strategy to rename the classname because the generated DAO class names are suffixed with "Home". I would like my generated DAO class names suffixed with "DAO", instead. I also want my generated DAOs to implement a DAO interface. How do I accomplish this?

Thanks!

_________________
pouncilt


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 05, 2008 4:23 pm 
Regular
Regular

Joined: Tue Jul 29, 2008 4:15 pm
Posts: 62
Location: Dallas, TX US
Okay I was able figure out how to name my DAOs with the "DAO" suffix from the following post: http://forum.hibernate.org/viewtopic.php?p=2319810&sid=3d37e60b91ef1b887b0fb16040a108e6. I must admit I didn't follow the conversation that well but enough to figure out the basics.

Using the Generic Exporter I can set up the following properties:
    File Pattern: {package-name}/../dao/{class-name}DAO.java
    Output directory: generated
    Template name: dao/daohome.ftl
    jdk5: true
    edj3: false
    sessionFactoryName: SessionFactory


Hur-ray! Sweet!

I still need to figure out how to do the following:
1. (Major Issue) -- Make my generated DAOs to implement a DAO interface.

2. (Minor Issue) -- The dao generation generates its own methods (persist(), attachDirty(), attachClean(), delete(), merge(), findById(), and findByExample()) . How can I replace these methods with my own named query methods as defined in the CommandQueries.hbm.xml file. Is this possible?

One way I am thinking about solving these 2 issues, is by playing with the daohome.ftl file. (Or better yet creating a new template based off the daohome.ftl file)

Any suggestions on how to do this?

Thanks!

_________________
pouncilt


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 05, 2008 6:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes, specific customization for daos should go to templates.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 05, 2008 11:59 pm 
Regular
Regular

Joined: Tue Jul 29, 2008 4:15 pm
Posts: 62
Location: Dallas, TX US
Max,

Are you familiar with the way I am configuring the Generic Exporter? I would like to know how do I configure the Generic Exporter further by configuring the Generic Exporter to use an interface when generating my DAOs.

How do I accomplish this in Hibernate Tools?

_________________
pouncilt


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 06, 2008 12:10 am 
Regular
Regular

Joined: Tue Jul 29, 2008 4:15 pm
Posts: 62
Location: Dallas, TX US
Max,

For the last day or so I've been trying to figure out how to rate on this site but I don't know how to do it. Do you know how?

Thanks!

_________________
pouncilt


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 06, 2008 2:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
pouncilt wrote:
Max,

Are you familiar with the way I am configuring the Generic Exporter? I would like to know how do I configure the Generic Exporter further by configuring the Generic Exporter to use an interface when generating my DAOs.

How do I accomplish this in Hibernate Tools?


You adjust the template to add the interface you want it to subclass.
if you need the interface to be generated too then you need an additional run of the generic exporter

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 06, 2008 2:52 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
pouncilt wrote:
Max,

For the last day or so I've been trying to figure out how to rate on this site but I don't know how to do it. Do you know how?

Thanks!


If you started the thread there should be a link or two below the answers about rating.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 06, 2008 12:06 pm 
Regular
Regular

Joined: Tue Jul 29, 2008 4:15 pm
Posts: 62
Location: Dallas, TX US
Max,

Thanks for your support. I was able to configure the daohome.ftl template to meet my needs. I am now able to make my DAOs implement my DAO interfaces.

At this point I am not going to worry about trying to remove the generated methods in the DAO because they should work fine as they are. But if I do need to remove them, I now know what to do; muck with the template.

I don't have a link in my view to rate the answers to my post. How do I resolve this?

Thanks again!

_________________
pouncilt


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 10, 2008 9:47 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
See the link under my points. It explains how and when the links work

_________________
Max
Don't forget to rate


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