gpt4 book ai didi

spring - Hibernate:无法对 DDL 应用约束

转载 作者:行者123 更新时间:2023-11-28 23:44:59 26 4
gpt4 key购买 nike

我在 Tomcat 7.0 中使用 Struts/Springs/Hibernate,在尝试启动服务器时我遇到了 hibernate 映射的问题。

控制台会打印:

Mapping class: path.vo.ObjectVO -> TABLE_NAME

对于 HibernateSessionFactory.xml 文件中的每个项目及其在 hibernate 文件夹中找到的关联 VO 对象。它将成功地遍历整个列表。

然而,一旦它看起来成功了,它就会在几个对象上阻塞,并给出这个错误:

WARN: Unable to apply constraints on DDL for path.vo.ObjectVO
java.lang.ClassNotFoundException: path.vo.ObjectVO

奇怪的是服务器过去运行良好。自从成功运行以来,我没有更改任何 hibernate 配置文件、VO 对象或数据库模式本身。我的研究只导致人们修复了对我不起作用的配置文件问题。

如有任何帮助,我们将不胜感激。这是我正在使用的一些文件。

HibernateSessionFactory.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<!-- Hibernate session factory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

<property name="dataSource">
<ref bean="dataSource"/>
</property>

<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>

<property name="mappingResources">
<list>
<value>hibernate/ClassA.hbm.xml</value>
<value>hibernate/ClassB.hbm.xml</value>
</list>
</property>
</bean>

ClassA.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="path.to.ClassAVO" table="CLASSA">
<id name ="Id" type="int">
<column name="ID"/>
<generator class="identity" />
</id>
<property name="somecolumn" type="string">
<column name="Somecolumn" length="24" not-null="true" />
</property>
...
</class>
</hibernate-mapping>

最佳答案

  1. 在 Hibernate 中禁止两个 PO 映射到同一个表。
  2. VO 应该包装数据并跨层传输,而不是持久化。
  3. 我建议您最好遵循开源社区熟悉并可以帮助您的分层设计的良好做法。

参见 Working with objects in hibernate

关于spring - Hibernate:无法对 DDL 应用约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15445909/

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