我是Hibernate的新手,我试图在Eclipse IDE中运行一些程序。我已经搜索了足够的问题,我找不到满足我案例的答案。我没有使用任何构建工具,如maven或任何依赖xml文件。
HibernateUtil.java看起来像这样
package com.hibernate;
import java.util.Date;
import org.hibernate.Session;
import com.hibernate.HibernateUtil;
import com.hibernate.Employee;
public class HibernateMain
{
public static void main(String[] args)
{
org.apache.log4j.BasicConfigurator.configure();
Employee emp = new Employee();
emp.setName("Pankaj");
emp.setRole("CEO");
emp.setInsertTime(new Date());
//Get Session
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
//start transaction
session.beginTransaction();
//Save the Model object
session.save(emp);
//Commit transaction
session.getTransaction().commit();
System.out.println("Employee ID="+emp.getId());
//terminate session factory, otherwise program won't end
HibernateUtil.getSessionFactory().close();
}
}
和HibernateMain.java看起来像这样
package com.hibernate;
import java.util.Date;
public class Employee
{
private int id;
private String name;
private String role;
private Date insertTime;
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 String getRole()
{
return role;
}
public void setRole(String role)
{
this.role = role;
}
public Date getInsertTime()
{
return insertTime;
}
public void setInsertTime(Date insertTime)
{
this.insertTime = insertTime;
}
}
和Employee.java看起来像这样
0 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Log4jLoggerProvider
18 [main] DEBUG org.hibernate.integrator.internal.IntegratorServiceImpl - Adding Integrator [org.hibernate.cfg.beanvalidation.BeanValidationIntegrator].
25 [main] DEBUG org.hibernate.integrator.internal.IntegratorServiceImpl - Adding Integrator [org.hibernate.secure.spi.JaccIntegrator].
36 [main] DEBUG org.hibernate.integrator.internal.IntegratorServiceImpl - Adding Integrator [org.hibernate.cache.internal.CollectionCacheInvalidator].
44 [main] DEBUG org.hibernate.integrator.internal.IntegratorServiceImpl - Adding Integrator [org.hibernate.envers.boot.internal.EnversIntegrator].
282 [main] INFO org.hibernate.Version - HHH000412: Hibernate Core {5.2.16.Final}
284 [main] INFO org.hibernate.cfg.Environment - HHH000206: hibernate.properties not found
332 [main] DEBUG org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver - Interpreting public/system identifier : [-//Hibernate/Hibernate Configuration DTD//EN] - [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd]
336 [main] WARN org.hibernate.orm.deprecation - HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead. Support for obsolete DTD/XSD namespaces may be removed at any time.
336 [main] DEBUG org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver - Recognized hibernate-configuration identifier; attempting to resolve on classpath under org/hibernate/
343 [main] DEBUG org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor - cfg.xml document did not define namespaces; wrapping in custom event reader to introduce namespace information
Hibernate Configuration loaded
org.hibernate.cfg.Configuration@4e7dc304
672 [main] DEBUG org.hibernate.integrator.internal.IntegratorServiceImpl - Adding Integrator [org.hibernate.cfg.beanvalidation.BeanValidationIntegrator].
672 [main] DEBUG org.hibernate.integrator.internal.IntegratorServiceImpl - Adding Integrator [org.hibernate.secure.spi.JaccIntegrator].
672 [main] DEBUG org.hibernate.integrator.internal.IntegratorServiceImpl - Adding Integrator [org.hibernate.cache.internal.CollectionCacheInvalidator].
673 [main] DEBUG org.hibernate.integrator.internal.IntegratorServiceImpl - Adding Integrator [org.hibernate.envers.boot.internal.EnversIntegrator].
Hibernate serviceRegistry created
org.hibernate.boot.registry.StandardServiceRegistryBuilder@53f65459
702 [main] INFO org.hibernate.spatial.integration.SpatialService - HHH80000001: hibernate-spatial integration enabled : true
710 [main] DEBUG org.hibernate.service.spi.ServiceBinding - Overriding existing service binding [org.hibernate.secure.spi.JaccService]
710 [main] DEBUG org.hibernate.service.spi.ServiceBinding - Overriding existing service binding [org.hibernate.spatial.integration.SpatialService]
711 [main] DEBUG org.hibernate.cfg.Configuration - Building session factory using provided StandardServiceRegistry
735 [main] DEBUG org.hibernate.cache.internal.RegionFactoryInitiator - Cache region factory : org.hibernate.cache.internal.NoCachingRegionFactory
750 [main] INFO org.hibernate.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.cfg.annotations.reflection.JPAMetadataProvider.<init>(Lorg/hibernate/boot/spi/MetadataBuildingOptions;)V
at org.hibernate.boot.internal.MetadataBuilderImpl$MetadataBuildingOptionsImpl.generateDefaultReflectionManager(MetadataBuilderImpl.java:742)
at org.hibernate.boot.internal.MetadataBuilderImpl$MetadataBuildingOptionsImpl.<init>(MetadataBuilderImpl.java:715)
at org.hibernate.boot.internal.MetadataBuilderImpl.<init>(MetadataBuilderImpl.java:127)
at org.hibernate.boot.MetadataSources.getMetadataBuilder(MetadataSources.java:135)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:654)
at com.hibernate.HibernateUtil.buildSessionFactory(HibernateUtil.java:25)
at com.hibernate.HibernateUtil.getSessionFactory(HibernateUtil.java:41)
at com.hibernate.HibernateMain.main(HibernateMain.java:25)
我收到以下错误
antlr-2.7.7
classmate-1.3.0
dom4j-1.6.1
hibernate-commons-annotations-5.0.1.Final
hibernate-core-5.2.16.Final
hibernate-jpa-2.1-api-1.0.0.Final
jandex-2.0.3.Final
javassist-3.20.0-GA
jboss-logging-3.3.1.Final
jboss-transaction-api_1.2_spec-1.0.1.Final
jta
persistence-api-1.0.2
slf4j-api-1.7.7
我已尝试从src / lib和scr / lib / required文件夹中删除/替换jar文件,但似乎没有任何效果。
我在src / lib / required文件夹下有以下Jar文件
{{1}}
由于