gpt4 book ai didi

java - 未找到 Hibernate-Component 类

转载 作者:行者123 更新时间:2023-12-01 21:31:51 27 4
gpt4 key购买 nike

我不明白这是怎么回事。这是我遇到的异常:

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

堆栈跟踪的第一个 block 是 Hibernate 异常,第二个跟踪 block 是与我的类的关系。

该类 ConsignacionesId 是由 Hibernate 自动生成的多属性 ID。

这是我的 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 生成的类:

enter image description here

如您所见,ConsignacionesId 就在那里。如有任何帮助,我们将不胜感激。

最佳答案

好吧,我缺少 hibernate hbm.xml 文件中类的完整路径。

这个:

    <?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”。在我生成所有类之前,它起作用了。

我希望这对某人有帮助。

发生这种情况是因为在“Hibernate Code Generation Cofigurations...”中我没有使用“package”字段。

“destiny”文件夹应该只有 src/main/java。

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

该路径位于“Hibernate Code Generation Configurations...”的“package”字段内

关于java - 未找到 Hibernate-Component 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37359325/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com