这是users.hbm.xml文件
<hibernate-mapping>
<class name="Users" table="USERS">
<id name="id" type="java.lang.Integer" column="ID">
<generator class="sequence">
<param name="sequence">users_seq</param>
</generator>
</id>
<property name="name" type="java.lang.String" column="NAME"></property>
<property name="pwd" type="java.lang.String" column="PWD"></property>
</class>
</hibernate-mapping>
这是users.cfg.xml文件
<session-factory>
<!-- 数据库驱动 -->
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<!-- 数据库地址 -->
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
<!-- 数据库用户名 -->
<property name="connection.username">young</property>
<!-- 数据库密码 -->
<property name="connection.password">yiyang</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="current_session_context_class">thread</property>
<property name="show_sql">true</property>
<mapping resource="Entity/Users.hbm.xml" />
</session-factory>
然后是测试类
public static void main(String[] args) {
Users user=new Users();
user.setName("张三");
user.setPwd("321");
Configuration config=new Configuration();
config.configure();
SessionFactory sessionfactory=config.buildSessionFactory();
Session session=sessionfactory.getCurrentSession();
Transaction tx=session.beginTransaction();
session.save(user);
tx.commit();
}
结果给抛出异常了
Exception in thread "main" org.hibernate.MappingException: entity class not found: Users
...
Caused by: java.lang.ClassNotFoundException: Users
新手刚学。高手请指教。。还是哪配置出错了。
没找到类,你的Users类有没有包名?
你可以
<class name="包名.Users" table="USERS">