开发者

Problem with mapping tag in hibernate configuration file

开发者 https://www.devze.com 2022-12-10 07:55 出处:网络
I am using hibernate annotations and when I do following everything works fine sessionFactory = new AnnotationConfiguration()

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 in开发者_Python百科to 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; *


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">

<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.

0

精彩评论

暂无评论...
验证码 换一张
取 消