问题描述
<?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;@Entitypublic class Student {private int id;private String name;private int age;@Idpublic 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 stubStudent 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
解决方案
导入jpa包