Initial SessionFactory creation failed.org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping class="com.ak.hibernate35sdy.model.Emp"/>提示错误具体配置:
Emp.java
package com.ak.hibernate35sdy.model;
import javax.persistence.Entity;
import javax.persistence.Id;/**
 *Hibernate35Sdy v1.1
 * 
 * @author AK
 * 
 */
@Entity
public class Emp { @Id
private int id; private String ename; private int sal; public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getEname() {
return ename;
} public void setEname(String ename) {
this.ename = ename;
} public int getSal() {
return sal;
} public void setSal(int sal) {
this.sal = sal;
}}<<数据库里有对于的表和字段>>

Hibernate.cfg.xml
<?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"><hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://127.0.0.1:3306/ak</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<!-- JDBC connection pool (use the built-in) -->
<!-- <property name="connection.pool_size">1</property>-->
<!-- SQL dialect -->
<!--
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
-->
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property> <!-- Disable the second-level cache  -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<mapping resource="com/ak/hibernate35sdy/model/Dept.hbm.xml" />
<mapping class="com.ak.hibernate35sdy.model.Emp" />
</session-factory>
</hibernate-configuration>测试程序(使用Junit测试,这里只是贴测试方法)
@Test
public void annotationHibernate(){
//// Configuration cfg = new AnnotationConfiguration();
//// SessionFactory sf = cfg.configure().buildSessionFactory();
//// Session session = sf.openSession();
Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); Emp emp = new Emp();
emp.setId(1);
emp.setEname("OKK");
emp.setSal(20000);
Serializable retVal = session.save(emp);
session.getTransaction().commit();
System.out.println(retVal);
}Jar包