-->
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.  [ 9 posts ] 
Author Message
 Post subject: Has <mapping class=""/> been deprecated in hibernate 5x?
PostPosted: Wed Jul 13, 2016 10:49 pm 
Newbie

Joined: Wed Jul 13, 2016 10:40 pm
Posts: 19
There is a problem when I use the annotation @Entity to mark my entity class that
when I use the hibernate 4x, the element <mapping class=""/> in the hibernate.cfg.xml can work,
but fail when hibernate 5x is used.

What's going on? I can not find the information about this aspect.


Top
 Profile  
 
 Post subject: Re: Is <mapping class=""/> has been deprecated in hibernate 5x?
PostPosted: Thu Jul 14, 2016 1:30 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1638
Location: Romania
Can you post your mappings? I don;t understand what's not working.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Is <mapping class=""/> has been deprecated in hibernate 5x?
PostPosted: Thu Jul 14, 2016 1:55 am 
Newbie

Joined: Wed Jul 13, 2016 10:40 pm
Posts: 19
mihalcea_vlad wrote:
Can you post your mappings? I don;t understand what's not working.


Oh,sorry. I means to the MappingException like: Unkown entity com.jerry.domain.Person
And I am sure that the annotation and configuration is ok, because the program can work in hibernate 4x.

But I have solved the problem. The reason following is a little complicated, but not relate to the element of <mapping class=""/>.

I use hibernate 5.3.1.Final, but my way to get a sessionFactory is as follow:
Code:
        public static final SessionFactory sessionFactory;
   static
   {
      try
      {
         
         Configuration cfg = new Configuration()
            .configure();
         
         ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
            .applySettings(cfg.getProperties()).build();
         sessionFactory = cfg.buildSessionFactory(serviceRegistry);
      }
      catch (Throwable ex)
      {
         System.err.println("Initial SessionFactory creation failed." + ex);
         throw new ExceptionInInitializerError(ex);
      }
   }


rather than

Code:
protected void setUp() throws Exception {
   // A SessionFactory is set up once for an application!
   final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
         .configure() // configures settings from hibernate.cfg.xml
         .build();
   try {
      sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
   }
   catch (Exception e) {
      // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
      // so destroy it manually.
      StandardServiceRegistryBuilder.destroy( registry );
   }
}



And I find the reason why the first method fails to work is that the Configuration class has removed the method parseMappingElement.
In a word, this method cannot be adapted in Hibernate 5x.

I dont know why the Hibernate makes this change. I am just a beginner, but I want to know why.


Top
 Profile  
 
 Post subject: Re: Is <mapping class=""/> has been deprecated in hibernate 5x?
PostPosted: Thu Jul 14, 2016 3:18 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1638
Location: Romania
The Configuration class represents a legacy bootstrapping logic which is no longer the preferred one for Hibernate 4 and 5. The new bootstrap logic allows better service handling and that's the reason we changed it. This is also documented in the migration guides as well.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Is <mapping class=""/> has been deprecated in hibernate 5x?
PostPosted: Thu Jul 14, 2016 3:51 am 
Newbie

Joined: Wed Jul 13, 2016 10:40 pm
Posts: 19
mihalcea_vlad wrote:
The Configuration class represents a legacy bootstrapping logic which is no longer the preferred one for Hibernate 4 and 5. The new bootstrap logic allows better service handling and that's the reason we changed it. This is also documented in the migration guides as well.


Thanks for your reply, your reply really encourages me, a biginner. My first language is not English, I am trying my best to be accustomed to solve problem with the docs or guides in the official website or some forums like this. Thank you.


Top
 Profile  
 
 Post subject: Re: Has <mapping class=""/> been deprecated in hibernate 5x?
PostPosted: Thu Jul 14, 2016 4:02 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1638
Location: Romania
Your welcome. I suggest you read the new User Guide which we rewrote from scratch. You might be interested in my Hibernate tutorial on my blog too.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Has <mapping class=""/> been deprecated in hibernate 5x?
PostPosted: Thu Jul 14, 2016 9:15 am 
Newbie

Joined: Wed Jul 13, 2016 10:40 pm
Posts: 19
mihalcea_vlad wrote:
Your welcome. I suggest you read the new User Guide which we rewrote from scratch. You might be interested in my Hibernate tutorial on my blog too.


Thank you for your recommending. I think I get a mapping problem among the relationship of few classes, so would you like to help me out? if yes, u can send me a e-mail to get the source code.

e-mali:601429364@qq.com


Top
 Profile  
 
 Post subject: Re: Has <mapping class=""/> been deprecated in hibernate 5x?
PostPosted: Thu Jul 14, 2016 10:41 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1638
Location: Romania
In my spare time, I have to write the High-Performance Java Persistence, meaning that I have no time for personal consulting.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Has <mapping class=""/> been deprecated in hibernate 5x?
PostPosted: Thu Jul 14, 2016 11:23 am 
Newbie

Joined: Wed Jul 13, 2016 10:40 pm
Posts: 19
mihalcea_vlad wrote:
In my spare time, I have to write the High-Performance Java Persistence, meaning that I have no time for personal consulting.


I have post a new topic about the problem in the forum. Thanks for your reply.


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