运行基本休眠程序时找不到类错误



我是Java Hibernate的新手。我正在编写一个基本程序,但收到此错误"找不到类包1。经理1"...经理 1 是我的主要课程。任何帮助将不胜感激。

我的文件如下所示:

1) hibernate/src/pack1/Employeeh.hbm.xml:

<hibernate-mapping package="pack1">
    <class name="Employeeh" table="EMPLOYEEH">
        <id name="empid" column="EMP_ID" type="long">
            <generator class="native"/>
        </id>
        <property name="fname" column="FNAME">
        </property>
        <property name="email"/>
        </class>
</hibernate-mapping>

2) hibernate/src/pack1/Employeeh.java:

package pack1;
public class Employeeh
{
private int empid;
private String fname;
private String email;
public int getEmpid()
{
    return empid;
}
..
}

3) 休眠/src/pack1/Manager1.java:

package pack1;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class Manager1
{
public static void main(String[] args)
{
    Configuration c1=new Configuration();
    c1.configure();
    SessionFactory sf=c1.buildSessionFactory();
    Session s1=sf.openSession();
    Employeeh e1=new Employeeh();
    e1.setEmpid(1);
    e1.setFname("gourav");
    e1.setEmail("a@b.com");
}
}

4) 休眠/src/休眠.cfg.xml:

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.username">gourav</property>
        <property name="hibernate.connection.password">baba</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
        <property name="hibernate.hbm2ddl.auto">create-drop</property>
       <mapping resource="pack1/Employeeh.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

提前谢谢..

我按照您发布的内容创建了一个新项目(我刚刚使用了MySql而不是Oracle)。结果对我来说是成功的...没有发生异常!

我会把我的所有文件发回给你...

Manager1Employeeh类与pack1包中的类完全相同。我的hibernate.cfg.xml是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYSTEM "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">root</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
        <property name="hibernate.hbm2ddl.auto">create-drop</property>
        <mapping resource="pack1/Employeeh.hbm.xml" />
    </session-factory>
</hibernate-configuration>

Employeeh.hbm.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="pack1">
    <class name="Employeeh" table="EMPLOYEEH">
        <id name="empid" column="EMP_ID" type="long">
            <generator class="native" />
        </id>
        <property name="fname" column="FNAME">
        </property>
        <property name="email" />
    </class>
</hibernate-mapping>

如果一切都相同,我的建议是检查所有文件是否都在您在配置文件中指定的位置,并记住您需要一个连接器来使用您的数据库。

希望这是有帮助的。

相关内容

最新更新