Hibernate error Org.hibernate.MappingException:Unknown entity: ....

Source: Internet
Author: User

This is due to the fact that the serviceregistry in Hibernate 4.x and 5.x have different
Hibernate 4.x
1. Create a Sessionfactory object
Sessionfactory Sessionfactory=null;
2. Create a configuration object that must be based on your basic configuration information and mapping relationships
Configuration Config=new configuration (). Configure ();
3. To create a Session object
Session Session=null;
4. Hibernate 4.X is introduced into the Serviceregistry interface with the registration information
Serviceregistry bulidserviceregistry = new Serviceregistrybuilder (). Applysettings (Config.getproperties ()). Buildserviceregistry ();
. Applysettings (Config.getproperties ()). build ();
Sessionfactory = Config.buildsessionfactory (bulidserviceregistry);
5. Get session
Session = Sessionfactory.opensession ();
Hibernate 5.x does not have a serviceregistrybuilder () method, but instead replaces it with the Standardserviceregistrybuilder () method
Serviceregistry serviceregistry = new Standardserviceregistrybuilder (). Applysettings (Config.getproperties ()). Build ();
However, this method does not get the entity class, so it can be written directly
Sessionfactory sessionfactory = null;
Configuration config = new configuration (). Configure ();

Session session =null;


Serviceregistry serviceregistry = new Standardserviceregistrybuilder (). Applysettings (Config.getproperties ()). Build ();

Sessionfactory =config.buildsessionfactory ();

Session = Sessionfactory.opensession ();

This article is from the "12901799" blog, please be sure to keep this source http://12911799.blog.51cto.com/12901799/1927538

Hibernate error Org.hibernate.MappingException:Unknown entity: ....

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.