-->
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: cant find annotated class using <mapping package> in c
PostPosted: Tue Oct 11, 2005 12:19 pm 
Newbie

Joined: Tue Oct 11, 2005 11:11 am
Posts: 2
I would like to use the <mapping package="..."> tag to find my annotated classes instead of the more explicit <mapping class="..">. But when I use the mapping package tag, it doesn't find my entities.

hibernate version
using hibernate annotations version 3.1 beta 6 with hibernate 3.1 rc1 and hibernate tools 3.0.0 alpha 4a

mapping files
Here is my ant task I am running:
Code:
<target name="db-gen-create-sql" depends="compile,create-hibernate-cfg,copy-generated-resources" description="creates ddl schema file from hibernate files">
   <echo message="creating table schema in ${build.dir} with the name of 'create-tables.sql'"/>

   <hibernatetool destdir="${build.dir}" >
      <annotationconfiguration configurationfile="${hibernate.config.file}" />
      <hbm2ddl export="true" console="false" drop="false" create="true"
                    outputfilename="${project.name}-create.ddl" delimiter=";"/>
   </hibernatetool>

</target>



Here is the configuration that DOESNT work
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:iesdevl</property>
        <property name="show_sql">true</property>
        <property name="dialect">org.hibernate.dialect.OracleDialect</property>
        <property name="query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
        <property name="hibernate.connection.username">xxxx</property>
        <property name="hibernate.connection.password">xxxx</property>
        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
      <property name="hibernate.default_schema">dbridge</property>
      <mapping package="edu.uwec.lts.adminservices"/>
    </session-factory>
</hibernate-configuration>


Only difference to make it work is to use <mapping class> instead
Code:
      <mapping class="edu.uwec.lts.adminservices.model.TestEntity"/>


when I use the mapping package tag, the ant task processes normally, but no schema is generated. When I use the <mapping class> tag the schema is generated. It seems to be ignoring the <mapping package> tag altogether.

off topic:
I am also trying to instantiate a hibernate session using an IoC framework (Spring) and passing in package names vs. explicit class references there too, and same problem occurs. I can show this code if you like, too.


Top
 Profile  
 
 Post subject: OOPS, My Bad
PostPosted: Tue Oct 18, 2005 12:12 pm 
Newbie

Joined: Tue Oct 11, 2005 11:11 am
Posts: 2
Upon further looking...

It was politely brought to my attention that I misunderstood the use of the <mapping package> tag for the hibernate config file (hibernate.cfg.xml). It, of course, is used to find package level annotations on package-info.java, not to provide a scan capability to find annotated classes within a package.

Although, this is what we were hoping for: a way to provide a pattern to indicate the annotated classes, rather than explicitly listing them. Due to the modularization of our project, we would rather not have a large list of all annotated entities centrally maintained, but be discovered in run-time depending on which modules were in the classpath for the given configuration.

Has anyone else desired this feature?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 18, 2005 12:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
ejb3 has autodiscovery stuff - dont know if that is applicable to hibernateannotations too

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: cant find annotated class using <mapping package> in c
PostPosted: Fri Oct 02, 2009 6:57 pm 
Newbie

Joined: Tue Oct 11, 2005 11:03 am
Posts: 4
You are in luck if you are using hibernate with Spring framework. Spring has a nice org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean bean implementation that takes a list of packages to scan for the annotated classes. The property is "packagesToScan" I think.


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.