Hibernate 4.1.3多租户空指针异常

时间:2012-05-23 20:38:10

标签: java hibernate

我在使用hibernate 4.1.3的新多租户功能时遇到了麻烦 我使用Glassfish 3.1和JPA2以及Hibernate 4.1.3作为提供者。

这是我的persistence.xml

<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="AuroraServicePU" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>jdbc/sqlserver/Aurora</jta-data-source>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
            <property name="hibernate.show_sql" value="false"/>
            <property name="hibernate.default_batch_fetch_size" value="100"/>
            <property name="hibernate.cache.use_second_level_cache" value="false"/>
            <property name="hibernate.cache.use_query_cache" value="false"/>
            <property name="hibernate.tenant_identifier_resolver" value="org.dna.aurora.web.TenantResolver" />
            <property name="hibernate.multiTenancy" value="DISCRIMINATOR" />
        </properties>
    </persistence-unit>
</persistence>

这是我尝试部署应用程序时遇到的异常。

  

信息:HCANN000001:Hibernate Commons Annotations {4.0.1.Final}信息:   HHH000412:Hibernate Core {4.1.3.Final}信息:HHH000206:   找不到hibernate.properties INFO:HHH000021:字节码提供程序名称   :javassist INFO:HHH000204:处理PersistenceUnitInfo [名称:   AuroraServicePU ...] SEVERE:调用类时出现异常   org.glassfish.persistence.jpa.JPADeployer准备方法SEVERE:   准备应用程序时出现异常SEVERE:日志消息为空。   java.lang.NullPointerException at   org.hibernate.engine.jdbc.internal.JdbcServicesImpl $ MultiTenantConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcServicesImpl.java:260)     在   org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:117)     在   org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)     在   org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)     在   org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)     在   org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)     在   org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2277)     在   org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2273)     在   org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1742)     在   org.hibernate.ejb.EntityManagerFactoryImpl。(EntityManagerFactoryImpl.java:76)     在   org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)     在   org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)     在   org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)     在   org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:205)     在   org.glassfish.persistence.jpa.PersistenceUnitLoader。(PersistenceUnitLoader.java:119)     在   org.glassfish.persistence.jpa.JPADeployer $ 1.visitPUD(JPADeployer.java:213)     在   org.glassfish.persistence.jpa.JPADeployer $ PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:486)     在   org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:220)     在   org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:166)     在   com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:870)     在   com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:410)     在   com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)     在   org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:370)     在   com.sun.enterprise.v3.admin.CommandRunnerImpl $ 1.execute(CommandRunnerImpl.java:355)     在   com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:370)     在   com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1067)     在   com.sun.enterprise.v3.admin.CommandRunnerImpl.access $ 1200(CommandRunnerImpl.java:96)     在   com.sun.enterprise.v3.admin.CommandRunnerImpl $ ExecutionContext.execute(CommandRunnerImpl.java:1247)     在   com.sun.enterprise.v3.admin.CommandRunnerImpl $ ExecutionContext.execute(CommandRunnerImpl.java:1235)     在   com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:465)     在   com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:222)     在   com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:168)     在   com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)     在   com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:234)     在   com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)     在   com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)     在   com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)     在   com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)     在   com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)     在   com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)     在   com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)     在   com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)     在   com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)     在   com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)     在com.sun.grizzly.ContextTask.run(ContextTask.java:71)at   com.sun.grizzly.util.AbstractThreadPool $ Worker.doWork(AbstractThreadPool.java:532)     在   com.sun.grizzly.util.AbstractThreadPool $ Worker.run(AbstractThreadPool.java:513)     在java.lang.Thread.run(Thread.java:619)

     

严重:准备应用程序时出现异常

更新: 我再次阅读了这些文档并注意到了这一重要的信息和平:

  

DISCRIMINATOR与分区(鉴别器)方法相关。   尝试在没有租户的情况下打开会话是错误的   使用此策略的标识符。该战略尚未实施   在Hibernate中从4.0和4.1开始。它的支持计划为5.0。

这是否真的意味着现在无法使用鉴别策略? 也许这就是整个问题?

任何帮助都会很棒。 谢谢, IDO。

1 个答案:

答案 0 :(得分:0)

您尚未指定Hibernate如何获取连接。您是否阅读过与此相关的文档? http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html_single/#d5e4583

具体而言: http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html_single/#d5e4658 http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html_single/#d5e4702