-->
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.  [ 6 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: 17
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: 1628
Location: Romania
Can you post your mappings? I don;t understand what's not working.


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: 17
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: 1628
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.


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: 17
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: 1628
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.


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