Hibernate未返回任何结果显示此错误信息:未将工厂绑定到JNDI,未配置JNDI名称

Hibernate未返回任何结果显示此错误信息:未将工厂绑定到JNDI,未配置JNDI名称,hibernate,orm,java-ee-6,jpa-2.0,glassfish-3,Hibernate,Orm,Java Ee 6,Jpa 2.0,Glassfish 3,我正在将JPA与hibernate一起使用,并试图连接到a数据源以检索信息,但当我运行应用程序时,没有收到任何错误,但在运行以下代码时,不会显示任何结果。这个问题源于我在设置环境以在hibernate上对JPA进行一些测试时发表的一篇文章玻璃鱼 日志文件显示了这一点 INFO: Not binding factory to JNDI, no JNDI name configured 我的日志文件 INFO: Processing PersistenceUnitInfo [ name:

我正在将JPA与hibernate一起使用,并试图连接到a数据源以检索信息,但当我运行应用程序时,没有收到任何错误,但在运行以下代码时,不会显示任何结果。这个问题源于我在设置环境以在hibernate上对JPA进行一些测试时发表的一篇文章玻璃鱼

日志文件显示了这一点

INFO: Not binding factory to JNDI, no JNDI name configured
我的日志文件

INFO: Processing PersistenceUnitInfo [
    name: DBAppPU
    ...]
INFO: Binding entity from annotated class: model.VMatterDetails
INFO: Binding Named query: VMatterDetails.findAll => SELECT v FROM VMatterDetails v
INFO: Binding Named query: VMatterDetails.findByMatterInfoStatus => SELECT v FROM VMatterDetails v WHERE v.matterInfoStatus = :matterInfoStatus
INFO: Binding Named query: VMatterDetails.findByMatterInfoRespLwyr => SELECT v FROM VMatterDetails v WHERE v.matterInfoRespLwyr = :matterInfoRespLwyr
INFO: Binding Named query: VMatterDetails.findByMatterID => SELECT v FROM VMatterDetails v WHERE v.matterID = :matterID
INFO: Binding Named query: VMatterDetails.findByMatterInfoMatterNum => SELECT v FROM VMatterDetails v WHERE v.matterInfoMatterNum = :matterInfoMatterNum
INFO: Bind entity model.VMatterDetails on table vMatterDetails
INFO: Hibernate Validator not found: ignoring
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
INFO: Using provided datasource
INFO: RDBMS: Microsoft SQL Server, version: 10.50.1600
INFO: JDBC driver: jTDS Type 4 JDBC Driver for MS SQL Server and Sybase, version: 1.2.5
INFO: Using dialect: org.hibernate.dialect.SQLServerDialect
INFO: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
INFO: Transaction strategy: org.hibernate.ejb.transaction.JoinableCMTTransactionFactory
INFO: instantiating TransactionManagerLookup: org.hibernate.transaction.SunONETransactionManagerLookup
INFO: instantiated TransactionManagerLookup
INFO: Automatic flush during beforeCompletion(): disabled
INFO: Automatic session close at end of transaction: disabled
INFO: Scrollable result sets: enabled
INFO: JDBC3 getGeneratedKeys(): enabled
INFO: Connection release mode: auto
INFO: Default batch fetch size: 1
INFO: Generate SQL with comments: disabled
INFO: Order SQL updates by primary key: disabled
INFO: Order SQL inserts for batching: disabled
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
INFO: Using ASTQueryTranslatorFactory
INFO: Query language substitutions: {}
INFO: JPA-QL strict compliance: enabled
INFO: Second-level cache: enabled
INFO: Query cache: disabled
INFO: Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
INFO: Optimize cache for minimal puts: disabled
INFO: Structured second-level cache entries: disabled
INFO: Statistics: disabled
INFO: Deleted entity synthetic identifier rollback: disabled
INFO: Default entity-mode: pojo
INFO: Named query checking : enabled
INFO: Check Nullability in Core (should be disabled when Bean Validation is on): disabled
INFO: building session factory
INFO: Not binding factory to JNDI, no JNDI name configured
INFO: Running hbm2ddl schema update
INFO: fetching database metadata
INFO: updating schema
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: table found: DB12248.dbo.vMatterDetails
INFO: columns: [clientinfostrextra1, matterinfobudgetdisbs, addressinfohomefaxphone, addressinfocompany, addressinfoaddrline2, addressinfoaddrline1, addressinfopager, matterinfodestroydate, matterinfolasttrust, matterinfobilledrcpts, addressinfolastname, matterinfoamtquoted, addressinfoattposition, matterinfolastsoadate, matterinfobilledhours, matterinfoextracasenote2, matterinfoextracasenote1, addressinfoaddrgroup, matterinfobilleddisbs, addressinfowebpage, addressinfohomephone, clientinfoextra2, clientinfoextra1, matterinfostatus, matterinfoextracasenote5, matterinfobilladdid2, matterinfoextracasenote6, matterinfoextracasenote3, matterinfoextracasenote4, addressinfomiddle, addressinfointernetaddr, matterinfoactivematter, clientinfomatterext, matterinfosparelong2, matterinfosparelong1, lawyerid, matterinforeferredbytype, matterid, matterinfobilladdid, matterinfosortname, matterinfodefrateamt, matterinfodefratetype, matterinfodocumentpath, matterinfototfees, matterinfoformatfile, addressinfocarphone, addressinfoextra, matterinfocredithold, matterinfocasenotes, matterinfortnrbal, addressinfohomeemail, matterinfofilelocation, matterinfoextracollectnote4, addressinfocity, matterinfochargeint, matterinfoextracollectnote3, matterinfoextracollectnote6, matterinfoextracollectnote5, addressinfosuffix, matterinfoopendate, matterinfobudgetfees, matterinfoflags, clientinfosortname, clientinfoclientdefault, addressinfofirst, matterinfointerestsettings, matterinfoextracollectnote2, clientinfomatterbase, matterinfoextracollectnote1, addressinfocode, matterinfosoaformat, addressinfocountry, matterinfofiledesc, matterinforeflwyr, matterinfousedefintrate, addressinfoaddrtype, matterinfomatternum, matterinforeferredby, matterinfotypeoflaw, addressinfocellphone, matterinfocollectionnotes, clientinfodocumentpath, matterinfobilledfees, matterinfosparestring, matterinfoarbal, matterinfolastbilled, matterinfolastrcptamount, matterinfototdisbs, addressinfoattlast, matterinfototalhours, matterinfotaxdisbs, matterinfosparedouble, matterinforesplwyr, matterinfolastfeedate, matterinfointrate, addressinfobusphone, addressinfoprov, matterinfocrossreference, addressinfofaxphone, matterinfolastrcptdate, matterinfototrcpts, addressinfotitle, matterinfolastdisbdate]
INFO: foreign keys: []
INFO: indexes: [pk__vmatterd__4d8e0b1a0b5cafea]
INFO: schema update complete
INFO: JNDI InitialContext properties:{}
INFO: Portable JNDI names for EJB VMatterDetailsFacade : [java:global/DBApp/VMatterDetailsFacade, java:global/DBApp/VMatterDetailsFacade!ejb.VMatterDetailsFacadeLocal]
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: Loading application DBApp at /DBApp
INFO: DBApp was successfully deployed in 3,374 milliseconds.
INFO: Find All Executing
INFO: Find All Return
ejbbean是

@Stateless
public class VMatterDetailsFacade implements VMatterDetailsFacadeLocal {
    public static final Logger log = Logger.getLogger("ejb.VMatterDetailsFacade");

    @PersistenceUnit(unitName = "DBAppPU")
    private EntityManagerFactory emf;    

    private List<VMatterDetails> matterDetailsList;

    protected EntityManager getEntityManager() {
        return emf.createEntityManager();
    }


    @Override
    public VMatterDetails find(String str) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<VMatterDetails> findAll() {
        log.info("Find All Executing");
        matterDetailsList = emf.createEntityManager().createNamedQuery("VMatterDetails.findAll").getResultList();
//        matterDetails.addAll(em2.createNamedQuery("VMatterDetails.findAll").getResultList());
        log.info("Find All Return");
        return matterDetailsList;
    }
    @Override
    public int count() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
@无状态
公共类VMatterDetailsFacade实现VMatterDetailsFacadolocal{
公共静态最终记录器log=Logger.getLogger(“ejb.vmatterdeailsfacade”);
@PersistenceUnit(unitName=“DBAppPU”)
私人实体管理工厂emf;
私人清单材料清单;
受保护的EntityManager getEntityManager(){
返回emf.createEntityManager();
}
@凌驾
公共VMatterDetails查找(字符串str){
抛出新的UnsupportedOperationException(“尚未支持”);
}
@凌驾
公共列表findAll(){
log.info(“查找所有正在执行的文件”);
matterDetailsList=emf.createEntityManager().createNamedQuery(“VMatterDetails.findAll”).getResultList();
//matterDetails.addAll(em2.createNamedQuery(“VMatterDetails.findAll”).getResultList());
log.info(“查找所有退货”);
返回matterDetailsList;
}
@凌驾
公共整数计数(){
抛出新的UnsupportedOperationException(“尚未支持”);
}
我的持久性xml是

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="DBAppPU" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>matterPool12248</jta-data-source>
    <properties>
      <property name="hibernate.hbm2ddl.auto" value="update"/>
    </properties>
  </persistence-unit>
</persistence>

org.hibernate.ejb.HibernatePersistence
马特波尔12248

您粘贴的日志未显示任何
错误
(或
致命
警告
)消息和您正在显示的特定消息只是告诉您,您没有将
SessionFactory
绑定到JNDI。这并没有什么问题,许多应用程序都不使用,这在使用JPA时并不真正相关。所以忽略此
INFO
信息消息

实际上,根据日志文件,一切看起来都很好:您的实体已被检测到,命名查询已被处理,模式已更新(因此与数据库的连接正常),等等

话虽如此,我还是要先激活SQL日志,看看到底发生了什么(这并不能解决问题,但仍然可以)。您可以在
persistence.xml中设置以下属性:

<!-- Echo all executed SQL to stdout -->
<property name="hibernate.show_sql" value="true"/>
并对数据库运行生成的SQL

第二件事,我建议使用注入容器管理的
EntityManager
,而不是使用应用程序管理的
EntityManager
(这是托管环境中的首选方式):

@无状态
公共类VMatterDetailsFacade实现VMatterDetailsFacadolocal{
公共静态最终记录器log=Logger.getLogger(“ejb.vmatterdeailsfacade”);
@PersistenceContext(unitName=“DBAppPU”)
私人实体管理者;
@凌驾
公共VMatterDetails查找(字符串str){
抛出新的UnsupportedOperationException(“尚未支持”);
}
@凌驾
公共列表findAll(){
log.info(“查找所有正在执行的文件”);
List matterDetailsList=em.createNamedQuery(“VMatterDetails.findAll”)
.getResultList();
log.info(“查找所有退货”);
返回matterDetailsList;
}
@凌驾
公共整数计数(){
抛出新的UnsupportedOperationException(“尚未支持”);
}
...
}
但是,这只是一个旁注,不能解决你的问题

首先检查生成的SQL并用结果更新您的问题。如果查询返回数据,请告诉我们您是如何检查bean方法不起作用的

工具书类
  • Hibernate核心文档

谢谢,hibernate配置没有问题,问题在于数据库中的表。我重新创建了DB结构,它工作得很好。
org.hibernate.SQL
@Stateless
public class VMatterDetailsFacade implements VMatterDetailsFacadeLocal {
    public static final Logger log = Logger.getLogger("ejb.VMatterDetailsFacade");

    @PersistenceContext(unitName = "DBAppPU")
    private EntityManager em;

    @Override
    public VMatterDetails find(String str) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List findAll() {
        log.info("Find All Executing");
        List matterDetailsList = em.createNamedQuery("VMatterDetails.findAll")
            .getResultList();
        log.info("Find All Return");
        return matterDetailsList;
    }
    @Override
    public int count() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    ...
}