Java 休眠未知实体(我知道以前有人问过…)

Java 休眠未知实体(我知道以前有人问过…),java,hibernate,Java,Hibernate,我知道这个问题已经被问了几千次了,但我不能解决我的问题。。。我在互联网上到处搜索,找不到解决方案。。。这就是错误 冬眠5.1 配置文件: } 主要 }这已经是一个经典问题:不能使用Hibernate 4配置代码来配置Hibernate 5 只需使用: Configuration configuration = new Configuration().configure(); sessionFactory = configuration.buildSessionFactory(); 如果您在hi

我知道这个问题已经被问了几千次了,但我不能解决我的问题。。。我在互联网上到处搜索,找不到解决方案。。。这就是错误

冬眠5.1

配置文件:

}

主要


}

这已经是一个经典问题:不能使用Hibernate 4配置代码来配置Hibernate 5

只需使用:

Configuration configuration = new Configuration().configure();
sessionFactory = configuration.buildSessionFactory();
如果您在hibernate.properties中有属性,则上述代码可以工作。您可以在hibernate.cfg.xml中找到它。我不记得了,也许,它也适用于这种情况


无论如何,您都可以使用新的Hibernate 5引导API

请添加Hibernate版本、xml配置、配置代码。@v.ladynev so。。。我编辑了这个问题…你能帮忙吗?是的。。。我想很好。。现在它说没有数据库selected@Hayden为什么不指定密码?尝试在日志或控制台中查看Hibernate是否加载了属性?im使用phpMyAdmin,my db没有password@Hayden您在hibernate日志中看到org.hibernate.dialent.mysqldialent了吗?现在有这些错误。。。1-解析JNDI名称[]时出错2-需要在环境或系统属性中指定类名,或作为小程序参数,或在应用程序资源文件中指定类名:java.naming.factory.initial 3-无法执行语句4-未选择数据库。。。对不起,我是新来的/noob在Hibernate
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jul 18, 2016 9:29:14 PM by Hibernate Tools 3.5.0.Final -->
<hibernate-mapping>
<class name="com.twentyone.User" table="USERS">
    <id name="id" type="int">
        <column name="ID" />
        <generator class="assigned" />
    </id>
    <property name="name" type="java.lang.String">
        <column name="NAME" />
    </property>
    <property name="goal" type="int">
        <column name="GOAL" />
    </property>
    <property name="total" type="int">
        <column name="TOTAL" />
    </property>
</class>
</hibernate-mapping>
package com.twentyone;

import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

public class HibernateUtilities {

private static SessionFactory sessionFactory;
private static ServiceRegistry serviceRegistry;

static {
    try {
        Configuration configuration = new Configuration().configure();

        serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
        sessionFactory = configuration.buildSessionFactory(serviceRegistry);

    } catch (HibernateException e1) {
        e1.printStackTrace();
        System.out.println("Problem");
    }
}

public static SessionFactory getSessionFactory() {
    return sessionFactory;
}
 package com.twentyone;

import org.hibernate.Session;

public class Program {
public static void main(String[] args) {

    System.out.println("Hayden");

    Session session = HibernateUtilities.getSessionFactory().openSession();
    session.beginTransaction();

    User user = new User();
    user.setName("Hayden");
    user.setGoal(250);
    session.save(user);

    session.getTransaction().commit();
    session.close();
    HibernateUtilities.getSessionFactory().close(); 

}
Configuration configuration = new Configuration().configure();
sessionFactory = configuration.buildSessionFactory();