-->
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.  [ 4 posts ] 
Author Message
 Post subject: Cannot get the named queries in the generated DAO
PostPosted: Thu Sep 04, 2008 11:58 am 
Newbie

Joined: Thu Sep 04, 2008 11:08 am
Posts: 4
Hibernate Tools version: 3.2.4.Alpha1

Hi,

I have spent two days setting up the Hibernate Tools for my project and I still cannot get the named queries to be in the DAO object.

- I have a User.hbm.xml generated from the DB and the reveng.xml file.
- I have declared the named query in a separate UserQueries.hbm.xml file with the fully qualified class name as prefix.
Code:
   <query name="cls.argodata.common.hibernate.pojo.User.findByLastName"><![CDATA[
          from User as user where user.lastName = :lastName
       ]]>
      <query-param name="lastName" type="string" />
   </query>

- These two hbm.xml files are included in the configuration mappings.
Code:
      <mapping resource="cls/argodata/common/hibernate/pojo/User.hbm.xml" />
      <mapping resource="cls/argodata/common/hibernate/pojo/UserQueries.hbm.xml" />

- I have a custom template file that is basically a copy of the provided one except for the logger variable that I have changed.

It seems that in that template file, the cfg.namedQueries.keySet() does not return anything: The foreach is not executed once.

However, when I try programmatically with the same files, I can execute that named query.

Any idea why the named query is not being included in the set?

PS: my hibernate.cfg.xml :
Code:
<hibernate-configuration>
    <session-factory name="sf">
      <!-- Enable Hibernate's automatic session context management -->
      <property name="current_session_context_class">thread</property>
      
      <!-- Disable the second-level cache -->
      <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
      
      <!-- JDBC connection pool (use the built-in) -->
      <property name="connection.pool_size">1</property>
      
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/xxx</property>
        <property name="hibernate.connection.username">xxx</property>
        <property name="hibernate.connection.password">xxx</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
       
      <!-- Mapping declarations -->
      <mapping resource="cls/argodata/common/hibernate/pojo/Sensor.hbm.xml" />   
      <mapping resource="cls/argodata/common/hibernate/pojo/Beacon.hbm.xml" />         
      <mapping resource="cls/argodata/common/hibernate/pojo/Device.hbm.xml" />         
      <mapping resource="cls/argodata/common/hibernate/pojo/Unit.hbm.xml" />         
      <mapping resource="cls/argodata/common/hibernate/pojo/User.hbm.xml" />
      <mapping resource="cls/argodata/common/hibernate/pojo/UserQueries.hbm.xml" />
   </session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2008 9:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
how are you doing the generation ?

ant file ? show the hibernate tool part.

eclipse ? any chance you have jdbc reverse engineering enabled ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2008 10:40 am 
Newbie

Joined: Thu Sep 04, 2008 11:08 am
Posts: 4
Hi,

I am using the Eclipse plugin to do the job. I have indeed "Reverse engineer from JDBC connection" checked.

I have unchecked the option and regenerated the DAOs and now it works. Was is specified somewhere in the documentation (just to know if I missed something)?

Any reason behind this "feature"? It sounds interesting to stay in synch with the DB schema and as well to have some additional HBM files to store named queries.

Thanks a lot for your help!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 10, 2008 1:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
reverse engineer means "extract entities from database".

So to do what you want have two generations - one with the reverse engineering and another where you have the added .hbm.xml and just generate from all.

_________________
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.  [ 4 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.