java - hibernate 中的 hbm 文件

标签 java hibernate spring orm hibernate-mapping

我正在对 Hibernate 应用程序进行一些更新。其中使用了Struts和Spring。 我们在配置文件(.cfg 文件)中输入 .hbm 文件。但是当将 spring 与 hibernate 应用程序一起使用时,我们会在 application context.xml 中进行条目。 但我在整个应用程序中找不到配置条目。 是否还有其他类我们配置了 .hbm 文件

我正在这里定义一个任务:link text 我正在更新一个应用程序。其中存在许多 hbm 文件。我还创建了一个新的 .hbm.xml 文件。现在我想配置这个新的 .hbm 文件。但在整个应用程序中我找不到配置所有 .hbm 文件的配置文件。

最佳答案

Hibernate 映射文件可以声明为:

创建配置时以编程方式

例如:

Configuration cfg = new Configuration()
    .addResource("Item.hbm.xml")
    .addResource("Bid.hbm.xml");

在 Hibernate 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 name="">

    <!-- Database connection settings -->
    <property name="connection.driver_class">${jdbc.driver}</property>
    <property name="connection.url">${jdbc.url}</property>
    <property name="connection.username">${jdbc.user}</property>
    <property name="connection.password">${jdbc.password}</property>

    ...

    <mapping resource="com/acme/Foo.hbm.xml"/>
    <mapping resource="com/acme/Bar.hbm.xml"/>
    ...
  </session-factory>
</hibernate-configuration>

在 Spring XML 应用程序上下文定义中

例如:

<beans>

  <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
    <property name="url" value="jdbc:hsqldb:hsql://localhost:9001"/>
    <property name="username" value="sa"/>
    <property name="password" value=""/>
  </bean>

  <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="myDataSource"/>
    <property name="mappingResources">
      <list>
        <value>product.hbm.xml</value>
      </list>
    </property>
    <property name="hibernateProperties">
      <value>
        hibernate.dialect=org.hibernate.dialect.HSQLDialect
      </value>
    </property>
  </bean>

</beans>

由于您使用的是 Spring,因此您很可能会使用上述方法。

资源

<小时/>

既然拥有资源,恐怕如果不展示更多内容(这可能是不可能的),您将无法获得任何更具体的帮助。如果需要,请进行文本搜索,内容无法隐藏。

关于java - hibernate 中的 hbm 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3986135/

相关文章:

java - 由于重复的 GUID,无法将数据库状态与 session org.hibernate.exception.ConstraintViolationException 同步

java - hibernate cfg文件

spring - TAM Webseal + spring 预认证

java - Spring-Retry 断路器会移动以恢复代码,在出现异常时无需任何重试尝试

java - maven - 用于 Spring 接口(interface)和实现的独立模块

java - 无法从 Elastic 6.0 获取数据 : “error” :”Content-Type header [text/plain] is not supported”, ”status”:406

java.lang.parseInt(UnknownSource) 尝试在 JDBC 中解析和插入行时出错

java - Android FacebookAPI - newMeRequest 永远不会返回到 onCompleted

java - Android - 应用程序不断因错误而崩溃 - 我认为这与首选项 fragment 有关

使用相对路径上传 Java Spring Web 应用程序文件