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

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包

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

报告相同问题?