Hibernate抛出NullPointerException - processFkSecondPassInOrder [英] Hibernate throwing NullPointerException - processFkSecondPassInOrder

查看:103
本文介绍了Hibernate抛出NullPointerException - processFkSecondPassInOrder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有一些关于Hibernate论坛的讨论,关于这个问题可能不太清楚。



我们使用JPA和Spring 3.0.5运行Hibernate 3.6.9。这个异常刚刚在两个版本之间弹出(因为它在一天前运行,而今天在部署中导致问题)。这可能与一些配置不正确的orm文件有关吗?我们有模型的orm.xml文件以及我们的命名查询。

 引起:java.lang.NullPointerException 
位于org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1481)
位于org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1419)
位于org.hibernate .cfg.Configuration.buildMappings(Configuration.java:1375)
在org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1519)
在org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator .java:193)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1100)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:689)
在org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFa处使用org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
ctory(LocalContainerEntityManagerFactoryBean.java:225)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods( AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)


解决方案

所以我们发现了这个问题。不幸的是,当Hibernate无法找到像嘿,虚拟,我无法找到您在orm文件中定义的FK的FK时,没有出现一些标准的配置异常。



在同一个模式/ db下有两个对象:

  class Person { 
长ID;
字符串名称;
地址;
...
}

所以Address对象是一对一作为组合键的一部分存在:

 <?xml version =1.0encoding =UTF-8? > 
< entity-mappings xmlns =http://java.sun.com/xml/ns/persistence/orm
xmlns:xsi =http://www.w3.org/2001 / XMLSchema-instance
xsi:schemaLocation =http://java.sun.com/xml/ns/persistence/orm
http://java.sun.com/xml/ns/persistence /orm_2_0.xsd
version =2.0>
< description> com.foo.Person实体映射< / description>
< package> com.foo< / package>
< schema> COMMON< / schema>
< access> FIELD< / access>
< entity class =com.foo.Personaccess =FIELDmetadata-complete =true>
< table name =PERSON/>
<属性>
< embedded-id name =id/>
< basic name =name>
< column name =NAME/>
< / basic>
< / attributes>
< / entity>
< embeddable class =com.foo.Person $ Idaccess =FIELD>
<属性>
...
<一对一名称=地址fetch =LAZYtarget-entity =com.foo.Address>
< join-column name =ADDR_CDinsertable =falseupdatable =false/>
< cascade>
< cascade-all />
< / cascade>
< / one-to-one>
< / attributes>
< / embeddable>
< / entity-mappings>

问题在于我们将Address对象移动到另一个数据库的另一个模式, orm文件(所以Address在复合键中仍然是一对一的)。

为了解决这个问题,我们断开了这个关系,并使Address瞬变,以便我们检索它是一种不同的方式,并消除了发生的异常。


Has anyone seen this message before?

There is some discussions on Hibernate forums with not much clarity as to what the issue might be.

We are running Hibernate 3.6.9 with JPA and Spring 3.0.5. This exception just popped up between two builds (as it worked a day ago and today is causing problems on deployment). Is this likely related to some incorrectly configured orm file? We have orm.xml files for our models as well as ones for our Named Queries.

Caused by: java.lang.NullPointerException
    at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1481)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1419)
    at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1375)
    at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1519)
    at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1100)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:689)
    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)

解决方案

So we found the problem. It is just unfortunate that the there isn't some standard Configuration Exception that is thrown when Hibernate is unable to find the FK like "Hey dummy, I can't find the FK that you have defined in the orm file."

We have two objects under the same schema/db:

class Person {
  Long id;
  String name;
  Address address;
  ...
}

So the Address object is a one to one that exists as part of a composite key:

<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
  http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
  version="2.0">
     <description>com.foo.Person Entity Mapping</description>
     <package>com.foo</package>
     <schema>COMMON</schema>
     <access>FIELD</access>
     <entity class="com.foo.Person" access="FIELD" metadata-complete="true">
        <table name="PERSON"/>
            <attributes>
                <embedded-id name="id"/>
                <basic name="name">
                        <column name="NAME"/>
                </basic>
            </attributes>
     </entity>
     <embeddable class="com.foo.Person$Id" access="FIELD">
        <attributes>
        ...
        <one-to-one name="address" fetch="LAZY" target-entity="com.foo.Address" >
            <join-column name="ADDR_CD" insertable="false" updatable="false"/>
            <cascade>
                <cascade-all/>
            </cascade>
        </one-to-one>
        </attributes>
     </embeddable> 
</entity-mappings>

The problem was that we moved the Address object to another schema on another db and left the relationship in the orm file (so Address was still a one-to-one in the composite key).

To fix it, we disconnected the relationship and made Address transient so that we retrieve it a different way and that removed the exception from happening.

这篇关于Hibernate抛出NullPointerException - processFkSecondPassInOrder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆