2016-09-03 1 views
0

Я пытаюсь написать мое первое приложение спящий режим аннотаций и ниже, являются вещи, которые я сделалorg.hibernate.MappingException: экземпляр AnnotationConfiguration требуется использовать <отображение класса =

package org.hibernate.pojo; 

import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.GeneratedValue; 
import javax.persistence.Id; 
import javax.persistence.Table; 

@Entity 
@Table(name="employee") 
public class Employee { 

@Id 
@GeneratedValue 
Integer id; 
@Column(name="Employee_Name") 
String userName; 
@Column(name="Address") 
String age; 



public Integer getId() { 
    return id; 
} 
public void setId(Integer id) { 
    this.id = id; 
} 
/** 
* Hi this is to test java commenting 
* @return 
*/ 
public String getUserName() { 
    return userName; 
} 
public void setUserName(String userName) { 
    this.userName = userName; 
} 
public String getAge() { 
    return age; 
} 
public void setAge(String age) { 
    this.age = age; 
} 

} 

Hibernate.config.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> 

     <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 
     <property name="hibernate.connection.password">$Ailaja12</property> 
     <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sessions</property> 
     <property name="hibernate.connection.username">root</property> 
     <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> 


     <property name="hibernate.bytecode.use_reflection_optimizer">false</property> 
     <!-- <property name="show_sql">true</property> --> 


     <!-- <mapping resource="org/hibernate/pojo/Employee.xml"></mapping> --> 
     <mapping class="org.hibernate.pojo.Employee"/> 
     <mapping resource="org/hibernate/pojo/Item.xml"></mapping> 
    </session-factory> 
</hibernate-configuration> 

Клиент

package org.hibernate.client; 

import org.hibernate.Session; 
import org.hibernate.SessionFactory; 
import org.hibernate.Transaction; 
import org.hibernate.cfg.AnnotationConfiguration; 
import org.hibernate.cfg.Configuration; 
import org.hibernate.pojo.Employee; 



     public class Client { 

      /** 
      * @param args 
      */ 
      public static void main(String[] args) { 

       //Starting hibernate environment in your application 
       Configuration conf = new Configuration(); 

       //2 Loading hibernate configuration file 
       conf.configure("hibernate.cfg.xml"); 

       SessionFactory factory=new AnnotationConfiguration().configure("hibernate.cfg.xml").buildSessionFactory(); 


       //SessionFactory factory = conf.buildSessionFactory(); 

       Session session = factory.getCurrentSession(); 

       Employee ee = new Employee(); 
       ee.setUserName("Kranthi"); 
       //ee.setId(123); 
       ee.setAge("Dallas"); 

       Transaction tx = session.beginTransaction(); 
       session.save(ee); 
       tx.commit(); 

       session.close(); 
       factory.close(); 
      } 

     } 

Я получаю ниже исключения

Исключение в потоке «основного» org.hibernate.MappingException: экземпляр AnnotationConfiguration требуется использовать

я пытался прибегая к помощи, но ни один из них не работал и ниже список банок, которые я использовал

antlr_2.7.6.jar 
asm-3.3.1.jar 
cglib-2.2.2.jar 
domj-1.3.jar 
ehcache.jar 
hibernate-3.2.jar 
javax.persistence.jar 
jta.jar 
mysql-connector.jar 
commonlogging.jar 
+0

приложение отлично работает с xml-конфигурацией –

ответ

0

Добавить ниже баночку вашего пути к классам: гибернации-annotations.3.3.0.GA.jar или добавить ниже зависимости в файл пом, если вы используете Maven проект

<dependency> 
    <groupId>hibernate-annotations</groupId> 
    <artifactId>hibernate-annotations</artifactId> 
    <version>3.3.0.GA</version> 
</dependency>