2016-08-11 8 views
0

Я создаю проект с Hibernate 4.3.5 и JBoss 7.1.1. Я дам вам скриншот о составе моего проекта:JBoss 7.1 и Hibernte 4.3.5 причина исключения

enter image description here

Банки на WEB-INF/lib являются:

enter image description here

Беллоу, являются rquired классы:

EntityDao.java 

public class EntityDao implements EntityDaoInterface<Book, Integer> 
 
{ 
 
\t private Session currentSession; 
 
\t private Transaction currentTransaction; 
 

 
\t public EntityDao() { 
 
\t } 
 

 
\t public Session openCurrentSession() { 
 
\t \t currentSession = getSessionFactory().openSession(); 
 
\t \t return currentSession; 
 
\t } 
 

 
\t public Session openCurrentSessionwithTransaction() { 
 
\t \t currentSession = getSessionFactory().openSession(); 
 
\t \t currentTransaction = currentSession.beginTransaction(); 
 
\t \t return currentSession; 
 
\t } 
 
\t 
 
\t public void closeCurrentSession() { 
 
\t \t currentSession.close(); 
 
\t } 
 
\t 
 
\t public void closeCurrentSessionwithTransaction() { 
 
\t \t currentTransaction.commit(); 
 
\t \t currentSession.close(); 
 
\t } 
 
\t 
 
\t private static SessionFactory getSessionFactory() { 
 
\t \t Configuration configuration = new Configuration().configure(); 
 
\t \t StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder() 
 
\t \t \t \t .applySettings(configuration.getProperties()); 
 
\t \t SessionFactory sessionFactory = configuration.buildSessionFactory(builder.build()); 
 
\t \t return sessionFactory; 
 
\t } 
 

 
\t public Session getCurrentSession() { 
 
\t \t return currentSession; 
 
\t } 
 

 
\t public void setCurrentSession(Session currentSession) { 
 
\t \t this.currentSession = currentSession; 
 
\t } 
 

 
\t public Transaction getCurrentTransaction() { 
 
\t \t return currentTransaction; 
 
\t } 
 

 
\t public void setCurrentTransaction(Transaction currentTransaction) { 
 
\t \t this.currentTransaction = currentTransaction; 
 
\t } 
 

 
\t public void persist(Person entity) { 
 
\t \t getCurrentSession().save(entity); 
 
\t } 
 

 
\t public void update(Person entity) { 
 
\t \t getCurrentSession().update(entity); 
 
\t } 
 

 
\t public void delete(Person entity) { 
 
\t \t getCurrentSession().delete(entity); 
 
\t } 
 

 
\t @SuppressWarnings("unchecked") 
 
\t public List<Person> findAllPersons() { 
 
\t \t List<Person> persons = (List<Person>) getCurrentSession().createQuery("from Person").list(); 
 
\t \t return persons; 
 
\t } 
 

 
\t public Person findPersonById(Integer id) { 
 
\t \t Person person = (Person) getCurrentSession().get(Person.class, id); 
 
\t \t return person; 
 
\t } 
 
\t 
 
}

EntityDaoInterface.java 

public interface EntityDaoInterface<T, Id extends Serializable> 
 
{ 
 
\t public void persist(T entity); 
 
\t public void update(T entity); 
 
\t public T findById(Id id); 
 
\t public void delete(T entity); 
 
\t public List<T> findAll(); 
 
\t public void deleteAll(); 
 
}

EntityService.java 

public class EntityService 
 
{ 
 
\t private static EntityDao entityDao; 
 

 
\t public EntityService() { 
 
\t \t entityDao = new EntityDao(); 
 
\t } 
 

 
\t public void persist(Person entity) { 
 
\t \t entityDao.openCurrentSessionwithTransaction(); 
 
\t \t entityDao.persist(entity); 
 
\t \t entityDao.closeCurrentSessionwithTransaction(); 
 
\t } 
 
\t 
 
\t public void update(Person entity) { 
 
\t \t entityDao.openCurrentSessionwithTransaction(); 
 
\t \t entityDao.update(entity); 
 
\t \t entityDao.closeCurrentSessionwithTransaction(); 
 
\t } 
 

 
\t public void remove(Person entity) { 
 
\t \t entityDao.openCurrentSessionwithTransaction(); 
 
\t \t entityDao.delete(entity); 
 
\t \t entityDao.closeCurrentSessionwithTransaction(); 
 
\t } 
 

 
\t public Person findPersonById(int id) { 
 
\t \t entityDao.openCurrentSession(); 
 
\t \t Person person = entityDao.findPersonById(id); 
 
\t \t entityDao.closeCurrentSession(); 
 
\t \t return person; 
 
\t } 
 

 
\t public List<Person> findAllPersons() { 
 
\t \t entityDao.openCurrentSession(); 
 
\t \t List<Person> persons = entityDao.findAllPersons(); 
 
\t \t entityDao.closeCurrentSession(); 
 
\t \t return persons; 
 
\t } 
 

 
\t 
 
\t public void deleteAll() { 
 
\t \t entityDao.openCurrentSessionwithTransaction(); 
 
\t \t entityDao.deleteAll(); 
 
\t \t entityDao.closeCurrentSessionwithTransaction(); 
 
\t } 
 

 
\t public EntityDao entityDao() { 
 
\t \t return entityDao; 
 
\t } 
 
}

Person.java 

@Entity 
 
@Table(name = "person") 
 
public class Person 
 
{ 
 
\t @Id  
 
\t @GeneratedValue(strategy = IDENTITY) 
 
\t @Column(name = "id", unique = true, nullable = false) 
 
\t private int id; 
 
\t 
 
\t @Column(name = "age") 
 
\t private int age; 
 
\t 
 
\t @Column(name= "name") 
 
\t String name; 
 
\t 
 
\t public Person() {} 
 

 
\t public Person(int id, int age, String name) { 
 
\t \t super(); 
 
\t \t this.id = id; 
 
\t \t this.age = age; 
 
\t \t this.name = name; 
 
\t } 
 

 
\t // With the methods: set, get, toString, hashCode, equals 
 
\t 
 
}

hibernate.cfg.xml 

<?xml version="1.0" encoding="utf-8"?> 
 
<!DOCTYPE hibernate-configuration PUBLIC 
 
\t "-//Hibernate/Hibernate Configuration DTD//EN" 
 
\t "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 
 
<hibernate-configuration> 
 
    <session-factory> 
 
\t <property name="hibernate.dialect">org.hibernate.dialect.SQLServer2008Dialect</property> 
 
\t <property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property> 
 
\t <property name="hibernate.connection.url">jdbc:sqlserver://localhost:1433;database=ccc</property> 
 
\t <property name="hibernate.connection.username">lm</property> 
 
\t <property name="hibernate.connection.password">pp</property> 
 
\t <property name="hibernate.hbm2ddl.auto">update</property> 
 
\t <property name="show_sql">true</property> 
 
\t <property name="hibernate.current_session_context_class">thread</property> 
 
\t <mapping class="com.esprit.entity.Book"/> 
 
\t <mapping class="com.esprit.entity.Person"/> 
 
\t </session-factory> 
 
</hibernate-configuration>

DataModelBeanD.java 

@SuppressWarnings("serial") 
 
@ManagedBean 
 
@ViewScoped 
 
public class DataModelBeanD implements Serializable 
 
{ 
 
    private List<Person> list; 
 
    private Person person = new Person(); 
 
    private boolean edit; 
 
    private EntityService entityService; 
 

 
    @PostConstruct 
 
    public void init() 
 
    { 
 
    \t entityService = new EntityService(); 
 
    \t list = entityService.findAllPersons(); 
 
    } 
 
}

После запуска проекта, появится следующее сообщение об ошибке:

08:32:54,297 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "HelloJPAHibernate.war" 
 
08:33:01,282 INFO [org.hibernate.annotations.common.Version] (http-localhost-127.0.0.1-8080-1) HCANN000001: Hibernate Commons Annotations {4.0.4.Final} 
 
08:33:01,290 INFO [org.hibernate.Version] (http-localhost-127.0.0.1-8080-1) HHH000412: Hibernate Core {4.3.5.Final} 
 
08:33:01,293 INFO [org.hibernate.cfg.Environment] (http-localhost-127.0.0.1-8080-1) HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.h2.Driver, hibernate.service.allow_crawling=false, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.max_fetch_depth=5, hibernate.format_sql=true, hibernate.generate_statistics=true, hibernate.connection.username=sa, hibernate.connection.url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE, hibernate.bytecode.use_reflection_optimizer=false, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=5} 
 
08:33:01,297 INFO [org.hibernate.cfg.Environment] (http-localhost-127.0.0.1-8080-1) HHH000021: Bytecode provider name : javassist 
 
08:33:01,317 INFO [org.hibernate.cfg.Configuration] (http-localhost-127.0.0.1-8080-1) HHH000043: Configuring from resource: /hibernate.cfg.xml 
 
08:33:01,318 INFO [org.hibernate.cfg.Configuration] (http-localhost-127.0.0.1-8080-1) HHH000040: Configuration resource: /hibernate.cfg.xml 
 
08:33:01,366 INFO [org.hibernate.cfg.Configuration] (http-localhost-127.0.0.1-8080-1) HHH000041: Configured SessionFactory: null 
 
08:33:01,453 WARN [org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl] (http-localhost-127.0.0.1-8080-1) HHH000402: Using Hibernate built-in connection pool (not for production use!) 
 
08:33:01,455 INFO [org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl] (http-localhost-127.0.0.1-8080-1) HHH000401: using driver [com.microsoft.sqlserver.jdbc.SQLServerDriver] at URL [jdbc:sqlserver://localhost:1433;database=ccc] 
 
08:33:01,457 INFO [org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl] (http-localhost-127.0.0.1-8080-1) HHH000046: Connection properties: {user=lm, password=****} 
 
08:33:01,458 INFO [org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl] (http-localhost-127.0.0.1-8080-1) HHH000006: Autocommit mode: false 
 
08:33:01,460 INFO [org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl] (http-localhost-127.0.0.1-8080-1) HHH000115: Hibernate connection pool size: 5 (min=1) 
 
08:33:03,123 INFO [org.hibernate.dialect.Dialect] (http-localhost-127.0.0.1-8080-1) HHH000400: Using dialect: org.hibernate.dialect.SQLServer2008Dialect 
 
08:33:03,255 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/HelloJPAHibernate].[Faces Servlet]] (http-localhost-127.0.0.1-8080-1) Servlet.service() for servlet Faces Servlet threw exception: java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index; 
 
at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:936) [hibernate-core-4.3.5.Final.jar:4.3.5.Final] 
 
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:824) [hibernate-core-4.3.5.Final.jar:4.3.5.Final] 
 
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3788) [hibernate-core-4.3.5.Final.jar:4.3.5.Final] 
 
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3742) [hibernate-core-4.3.5.Final.jar:4.3.5.Final] 
 
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1410) [hibernate-core-4.3.5.Final.jar:4.3.5.Final] 
 
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844) [hibernate-core-4.3.5.Final.jar:4.3.5.Final] 
 
at com.esprit.dao.EntityDao.getSessionFactory(EntityDao.java:48) [classes:] 
 
at com.esprit.dao.EntityDao.openCurrentSession(EntityDao.java:25) [classes:] 
 
at com.esprit.dao.EntityService.findAllPersons(EntityService.java:86) [classes:] 
 
at com.esprit.crud.dynamic.DataModelBeanD.init(DataModelBeanD.java:37) [classes:] 
 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_55] 
 
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_55] 
 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_55] 
 
at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.7.0_55]

Я не мог знать, что пропустили, не могли бы вы помочь мне решить эту проблему. Любое предложение оценивается. Спасибо заранее.

ответ

0

Я решил свою проблему, сделав Hibernate 4.2.21 вместо Hibernate 4.3.5. Затем я вновь создать метод getSessionFactory() класса EntityDao.java как ниже:

private static SessionFactory getSessionFactory() \t \t \t 
 
\t { 
 
\t \t if (sessionFactory == null) { 
 
\t   Configuration configuration = new Configuration().configure(); 
 
\t   ServiceRegistryBuilder registry = new ServiceRegistryBuilder(); 
 
\t   registry.applySettings(configuration.getProperties()); 
 
\t   ServiceRegistry serviceRegistry = registry.buildServiceRegistry(); 
 
\t   
 
\t   sessionFactory = configuration.buildSessionFactory(serviceRegistry);   
 
\t  } 
 
\t \t return sessionFactory; 
 
\t }

 Смежные вопросы

  • Нет связанных вопросов^_^