找不到Hibernate-Component类 [英] Hibernate-Component class not found

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

问题描述

我不明白这里发生了什么.这是我得到的例外:

I don't understand what is going on here. This is the exception I'm getting:

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [file:/C:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/demoBancoWeb/WEB-INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.component.PojoComponentTuplizer]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
.
.
.
Caused by: java.lang.ClassNotFoundException: co.edu.icesi.demo.modelo.ConsignacionesId
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1305)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1139)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at org.hibernate.internal.util.ReflectHelper.classForName(ReflectHelper.java:193)
    at org.hibernate.mapping.Component.getComponentClass(Component.java:138)
    ... 42 more

堆栈跟踪的第一块是Hibernate异常,跟踪的第二块是与我的类的关系.

The first block of stack trace is the Hibernate exception and the second block of trace is the relation with my classes.

该类ConsignacionesId由Hibernate自动生成为多属性ID.

这是我的休眠cfg.xml:

This is my 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.bytecode.use_reflection_optimizer">false</property>
  <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
  <property name="hibernate.connection.password">admin</property>
  <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/banco</property>
  <property name="hibernate.connection.username">postgres</property>
  <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
  <property name="hibernate.search.autoregister_listeners">false</property>
  <property name="show_sql">true</property>
  <mapping resource="co/edu/icesi/demo/modelo/Clientes.hbm.xml"/>
  <mapping resource="co/edu/icesi/demo/modelo/Cuentas.hbm.xml"/>
  <mapping resource="co/edu/icesi/demo/modelo/TiposUsuarios.hbm.xml"/>
  <mapping resource="co/edu/icesi/demo/modelo/TiposDocumentos.hbm.xml"/>
  <mapping resource="co/edu/icesi/demo/modelo/Consignaciones.hbm.xml"/>
  <mapping resource="co/edu/icesi/demo/modelo/Usuarios.hbm.xml"/>
  <mapping resource="co/edu/icesi/demo/modelo/Retiros.hbm.xml"/>

    <mapping resource="co/edu/icesi/demo/modelo/Consultas.hbm.xml"/>

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

最后,这是我的Hibernate生成的类:

And finally, this are my classes generated by Hibernate:

如您所见,ConsignacionesId就在其中. 感谢您的帮助.

推荐答案

好吧,我在休眠的hbm.xml文件中缺少类的完整路径.

Ok, I was missing the complete path to my classes inside the hibernate hbm.xml files.

此:

    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- Generated 01-feb-2016 18:51:34 by Hibernate Tools 4.0.0 -->
    <hibernate-mapping>
        <class name="Clientes" table="clientes" schema="public">
            <id name="cliId" type="long">
                <column name="cli_id" precision="10" scale="0" />
                <generator class="assigned" />
            </id>
            <many-to-one name="tiposDocumentos" class=
.
.
.

必须看起来像这样:

    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- Generated 01-feb-2016 18:51:34 by Hibernate Tools 4.0.0 -->
    <hibernate-mapping>
        <class name="co.edu.icesi.demo.modelo.Clientes" table="clientes" schema="public">
            <id name="cliId" type="long">
                <column name="cli_id" precision="10" scale="0" />
                <generator class="assigned" />
            </id>
            <many-to-one name="tiposDocumentos" class="

.
.
.

所以我只粘贴了"co.edu.icesi.demo.modelo".在所有生成的类之前,它就起作用了.

So I just pasted "co.edu.icesi.demo.modelo." before all my generated classes, and it worked.

我希望这对某人有帮助.

I hope this helps somebody.

发生这种情况是因为在休眠代码生成配置..."中,我没有使用包"字段.

This happened because in the "Hibernate Code Generation Cofigurations..." I DID NOT use the field "package".

目的地"文件夹应仅为src/main/java.

The "destiny" folder should be only src/main/java.

不要创建将自己保存生成的类的包.就我而言,请勿创建 co.edu.icesi.demo.modelo .

Don't create the package that will hold your generated classes by yourself. In my case, don't create co.edu.icesi.demo.modelo.

该路径位于休眠代码生成配置..."的程序包"字段中

That path goes inside the "package" field of "Hibernate Code Generation Configurations..."

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

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