【问题标题】:com.sun.jdi.InvocationException occurred invoking method in "new Configuration().configure().buildSessionFactory()"com.sun.jdi.InvocationException 在“new Configuration().configure().buildSessionFactory()”中发生调用方法
【发布时间】:2016-01-08 12:28:07
【问题描述】:

当我尝试buildSessionFactory 时,我看到了NullPointerException。但是,在 Eclipse 的调试模式下单击异常对象时,我看到的消息是 com.sun.jdi.InvocationException occurred invoking method.

我是在引入新的Entity 类之后才看到这种行为。类绑定到的表存在。没有错别字。 hibernate.cfg.xml 也解析成功。在 hibernate 尝试将新类绑定到表后抛出一个致命异常。

  1. hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
    <property name="hibernate.connection.url">jdbc:oracle:thin:@lvsspldb06.qa.xxxx.com:1556:ICMDBTST</property>
    <property name="hibernate.connection.username">ICMAPP</property>
    <property name="hibernate.connection.password">ICMAPP</property>
    <property name="show_sql">true</property>
    <mapping class="com.xxxx.top.entity.Release"></mapping>
    <mapping class="com.xxxx.top.entity.Package"></mapping>
    <mapping class="com.xxxx.top.entity.Top"></mapping>
    <mapping class="com.xxxx.top.entity.PortAssignment"></mapping>
  </session-factory>
</hibernate-configuration>
  1. desc package_portassignment; 给出一个输出。这样就可以确认该表存在。

  2. 控制台日志

. . . 22:03:02.239 [main] DEBUG org.hibernate.cfg.Configuration - 会话工厂配置 [null] 命名类 [com.xxxx.top.entity.Release] 用于映射 22:03:03.031 [main] DEBUG org.hibernate.cfg.Configuration - 会话工厂配置 [null] 命名类 [com.xxxx.top.entity.Package] 用于映射 22:03:03.589 [main] DEBUG org.hibernate.cfg.Configuration - 会话工厂配置 [null] 命名类 [com.xxxx.top.entity.Top] 用于映射 22:03:04.076 [main] DEBUG org.hibernate.cfg.Configuration - 会话工厂配置 [null] 命名类 [com.xxxx.top.entity.PortAssignment] 用于映射 22:03:04.080 [main] INFO org.hibernate.cfg.Configuration - HHH000041:配置的 SessionFactory:null . . . 22:03:13.287 [main] 调试 org.hibernate.cfg.Configuration - 处理 hbm.xml 文件 22:03:13.287 [main] DEBUG org.hibernate.cfg.Configuration - 处理带注释的类 22:03:13.305 [main] DEBUG org.hibernate.cfg.AnnotationBinder - 来自注释类的绑定实体:com.xxxx.top.entity.Release 22:03:13.415 [main] DEBUG org.hibernate.cfg.Ejb3Column - 绑定列:Ejb3DiscriminatorColumn{logicalColumnName'DTYPE',discriminatorTypeName='string'} 22:03:13.422 [main] DEBUG org.hibernate.cfg.AnnotationBinder - 没有为“javax.persistence.sharedCache.mode”指定值;使用未指定 22:03:13.450 [main] DEBUG o.h.cfg.annotations.EntityBinder - 使用实体名称 Release 导入 22:03:13.470 [main] DEBUG o.h.cfg.annotations.EntityBinder - 在表 release_release 上绑定实体 com.xxxx.top.entity.Release 22:03:13.567 [main] 调试 org.hibernate.cfg.Ejb3Column - 绑定列:Ejb3Column{table=org.hibernate.mapping.Table(release_release), mappingColumn=id, . . . 22:03:13.646 [main] DEBUG org.hibernate.cfg.Ejb3Column - 绑定列:Ejb3DiscriminatorColumn{logicalColumnName'DTYPE',discriminatorTypeName='string'} 22:03:13.646 [main] DEBUG org.hibernate.cfg.AnnotationBinder - 没有为“javax.persistence.sharedCache.mode”指定值;使用未指定 22:03:13.646 [main] DEBUG o.h.cfg.annotations.EntityBinder - 使用实体名称包导入 22:03:13.647 [main] DEBUG o.h.cfg.annotations.EntityBinder - 在表 package_package 上绑定实体 com.xxxx.top.entity.Package . . . 22:03:13.699 [main] DEBUG org.hibernate.cfg.AnnotationBinder - 没有为“javax.persistence.sharedCache.mode”指定值;使用未指定 22:03:13.699 [main] DEBUG o.h.cfg.annotations.EntityBinder - 使用实体名称导入顶部 22:03:13.700 [main] DEBUG o.h.cfg.annotations.EntityBinder - 在表 top_top 上绑定实体 com.xxxx.top.entity.Top 22:03:13.710 [main] 调试 org.hibernate.cfg.Ejb3Column - 绑定列:Ejb3Column{table=org.hibernate.mapping.Table(top_top), mappingColumn=id, insertable=true, updatable=true, unique=true } . . . 22:03:13.719 [main] DEBUG org.hibernate.cfg.AnnotationBinder - 没有为“javax.persistence.sharedCache.mode”指定值;使用未指定 22:03:13.719 [main] DEBUG o.h.cfg.annotations.EntityBinder - 使用实体名称 PortAssignment 导入 22:03:13.719 [main] DEBUG o.h.cfg.annotations.EntityBinder - 在表 package_portassignment 上绑定实体 com.xxxx.top.entity.PortAssignment 此处抛出 FATAL 异常
  1. 新增的Entity类

PortAssignment.java。无法在这个问题中发布它,因为 stackoverflow 让我对格式感到非常不满。

【问题讨论】:

  • 你也可以添加完整的堆栈跟踪吗?
  • 我看到NullPointerException 没有堆栈跟踪信息。与异常相关的详细消息也是空的。当我尝试检查异常对象时,线程突然结束。
  • 在FATAL exception is thrown here之后添加更多行。
  • Stackoverflow 不允许我添加这些行,因为它认为这是未正确格式化的代码。但是,我可以解释致命的异常。当我在类加载期间尝试初始化静态成员时会发生异常,这反过来会引发ExceptionInInitializerError。我将发布新课程以供您参考。

标签: java hibernate


【解决方案1】:

我重写了新类,错误消失了。我承认,我很尴尬,但我认为注释 Column(name=...) 中有一个属性有错字。

我假设这会导致 Hibernate 的一个内部类(特别是 org.hibernate.annotations.common.reflection.XClass.getDeclaredProperties)中出现 NullPointerException。

感谢 Channa Jayamuni 的想法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-12
    • 1970-01-01
    • 2013-01-13
    • 1970-01-01
    相关资源
    最近更新 更多