org.hibernate.MappingException: Unknown entity: annotations.Users

前端 未结 19 1653
情歌与酒
情歌与酒 2020-12-01 07:11

Consider the hierarchy :

\"enter

And the following classes and xml :

19条回答
  •  孤街浪徒
    2020-12-01 07:59

    If you are using 5.0x version,configuration with standard service registry is deprecated.

    Instead you should bootstrap it with Metadata: In your HibernateUtil class, you should add

    private static SessionFactory buildSessionFactory() {
        try {           
            StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder()
                .configure( "hibernate.cfg.xml" )
                .build();
    
            Metadata metadata = new MetadataSources( standardRegistry )
                .getMetadataBuilder()
                .build();
    
            return metadata.getSessionFactoryBuilder().build();
        } catch(...) {
            ...
        }
    }
    

提交回复
热议问题