gpt4 book ai didi

java - hibernate 中的 hbm 文件

转载 作者:行者123 更新时间:2023-12-02 08:28:30 24 4
gpt4 key购买 nike

我正在对 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/

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