tags:

views:

166

answers:

1

I am using hibernate annotations and when I do following everything works fine

sessionFactory = new AnnotationConfiguration()
                                .addPackage("istreamcloudframework.objectmodel.member")
                                .addAnnotatedClass(User.class)
     .buildSessionFactory();

but I wanted to avoid specifying all the classes in this manner so I tried taking that into hibernate config file in following manner,


    mapping package="istreamcloudframework.objectmodel.member"
    mapping class="istreamcloudframework.objectmodel.member.User"

I get following error,


org.hibernate.MappingException: Unknown entity: istreamcloudframework.objectmodel.member.User

Whats going wrong over here?

P.S: I have checked all the annotation imports and its not org.hibernate.annotations.Entity. I am using javax.persistence. imports; *

+1  A: 

You must use AnnotationConfiguration instance to process XML file containing your configuration, but you should be able to specify your classes there. See Hibernate Annotations documentation for more details.

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;

<hibernate-configuration>
  <session-factory>
    <mapping package="istreamcloudframework.objectmodel.member" />
    <mapping class="istreamcloudframework.objectmodel.member.User" />
  </session-factory>
</hibernate-configuration>

Creating session factory:

SessionFactory sessionFactory = new AnnotationConfiguration()
 .configure().buildSessionFactory();

Also note that it's not necessary to map package (doing so won't map classes in said package) unless you have package-level annotations.

ChssPly76
Chetan