shanYangBoy 2013-07-22 10:20
浏览 343
已采纳

Exception in thread "main" java.lang.NoClassDefFoundError:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>

    <session-factory>
        <property name="hbm2ddl.auto">update</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/xuyang</property>
        <property name="connection.username">root</property>
        <property name="connection.password">789</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="myeclipse.connection.profile">mysql</property>
        
        
        <mapping class="com.xuyang.Demo.Student"/> 
    </session-factory>

</hibernate-configuration>
package com.xuyang.Demo;

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class Student {
    private int id;
    private String name;
    private int age;
    @Id
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    
}
package com.xuyang.Demo;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;


public class Just_test {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        
        
        Student st=new Student();
        st.setId(1);
        st.setName("yang");
        st.setAge(20);
        
        Configuration cfg = new Configuration();    //读取配置hibernate文件
        SessionFactory  sf = cfg.configure().buildSessionFactory();
        Session sess = sf.openSession();
        sess.save(st);                            //保存对象
        sess.getTransaction().commit();
        sess.close();    
        sess.close();
       }
}

    自学hibernate  的时候遇见的问题我用的hibernate是4.2版本  运行时出现error:Exception in thread "main" java.lang.NoClassDefFoundError: javax/persistence/Cacheable

  • 写回答

1条回答 默认 最新

  • QiangGe2Dai 2013-07-22 10:31
    关注

    导入jpa包

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 判断两个表是否完全相同
  • ¥20 工控机出现散热器转一下停一下这种情况,是什么原因造成的
  • ¥15 双显卡,启动docker容器报错。
  • ¥15 想编写一个期货跨期套利的程序
  • ¥15 一个线程在sleep的时候set一个信号会起作用吗
  • ¥100 需求高精度PT100设计电路和算法
  • ¥15 单片机配网,继电器开关,广播
  • ¥60 Qcustomplot绘制实时动态曲线
  • ¥20 运用matlab画x-y图
  • ¥15 用idea运行项目,运行tomcat报错:断言失败