使用Glassfish服务器将Hibernate集成到JSF项目中

时间:2016-07-17 08:27:28

标签: eclipse hibernate jsf glassfish

我在Eclipse中使用GlassFish服务器,并尝试将hibernate-release-5.1.0.Final插入到JSF项目中。我已经尝试了几个步骤,但没有确定。

  • 我已将Hibernate Jars放在GlassFisch directrory glassfish4\bin中并重新启动服务器。
  • 我将它们放在以下作品集glassfish4\glassfish\bin中,然后重新启动了GlassFisch服务器。
  • 我将Hibernate jar放在WEB-INF / lib
  • 我将此部分.addResource("/resources/person.hbm.xml")添加到CreatePersonDemo类。
  • 我用jboss-logging.jar
  • 替换了glassfish4\glassfish\modules目录中的jboss-logging-3.3.0.Final.jar

CreatePersonDemo

package com.backing;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import com.model.Person;



public class CreatePersonDemo {

    public static void main(String[] args) {
        // create session factory.
//      SessionFactory factory = new Configuration()
//              .configure("/resources/hibernate.cfg.xml")
//              .addAnnotatedClass(Person.class)
//              .buildSessionFactory();
        SessionFactory factory = new Configuration().configure("/resources/hibernate.cfg.xml")
                .addResource("/resources/person.hbm.xml")
                .addAnnotatedClass(Person.class)
                .buildSessionFactory();

        // create a session.
        Session session = factory.getCurrentSession();
        System.out.println("CreateStudentDemo");

    }
}

hibernate.cfg.xml中

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM 
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/GMapsYahooMeshup</property>
        <property name="connection.username">root</property>
        <property name="connection.password"></property>

        <property name="connection.pool_size">1</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="current_session_context_class">thread</property>
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <property name="show_sql">true</property>
        <property name="current_session_context_class">thread</property>
        <mapping resource="resources/person.hbm.xml" /> 
        <!-- <mapping class ="com.Model.Person" /> -->

    </session-factory>
</hibernate-configuration>

person.hbm.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
 "-//Hibernate/Hibernate Mapping DTD//EN"
 "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="Person" table="person">
        <meta attribute="class-description">
            This class contains the person detail.
        </meta>
        <id name="id" type="int" column="id">
            <generator class="native" />
        </id>
        <property name="full_name" column="full_name" type="string" />
        <property name="email " column="email " type="string" />
        <property name="location" column="location" type="string" />
        <property name="pwd" column="pwd" type="string" />
    </class>
</hibernate-mapping>

Person.Java

package com.model;   

public class Person {
    private int id;
    private String full_name;
    private String email;
    private String location;
    private String pwd;
    public Person(int id, String full_name, String email, String location, String pwd) {
        super();
        this.id = id;
        this.full_name = full_name;
        this.email = email;
        this.location = location;
        this.pwd = pwd;
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getFull_name() {
        return full_name;
    }
    public void setFull_name(String full_name) {
        this.full_name = full_name;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getLocation() {
        return location;
    }
    public void setLocation(String location) {
        this.location = location;
    }
    public String getPwd() {
        return pwd;
    }
    public void setPwd(String pwd) {
        this.pwd = pwd;
    }
}

错误

org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=root, password=****}
Jul 17, 2016 10:24:52 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.internal.CoreMessageLogger.debugf(Ljava/lang/String;I)V
    at org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.java:34)
    at org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.java:19)
    at org.hibernate.engine.jdbc.connections.internal.PooledConnections$Builder.build(PooledConnections.java:138)
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildPool(DriverManagerConnectionProviderImpl.java:110)
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:74)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:234)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:692)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
    at com.backing.CreatePersonDemo.main(CreatePersonDemo.java:22)

项目结构

enter image description here

0 个答案:

没有答案