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.PersonAnd 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 thanCode:
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.