【问题标题】:My Configuration file is unable to find the hibernate mapping我的配置文件找不到休眠映射
【发布时间】:2017-11-07 03:16:38
【问题描述】:

enter image description hereThis is my project

请检查我的配置文件和映射文件,即使它们在同一个文件夹中,配置文件也无法找到映射资源。

我的休眠配置文件

[>

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>

<!-- Related to the connection START -->
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver
</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:3306:XE</property>
<property name="connection.user">root</property>
<property name="connection.password">maherukh</property>
<!-- Related to the connection END -->

<!-- Related to hibernate properties START -->
<property name="show_sql">true </property>
<property name="dialet">org.hibernate.dialect.OracleDialect </property>
<property name="hbm2ddl.auto">update </property>
<!-- Related to hibernate properties END -->

<!-- Related to mapping START -->
<mapping resource="Product.hbm.xml" />
<!-- Related to the mapping END -->

</session-factory>
</hibernate-configuration>][2]

我的休眠映射文件

<?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="Product" table="PRODUCTS">

<id name="productId" column="pid"  >
<generator class="assigned" />
</id>

<property name="proName" column="pname" />
<property name="price"/>

</class>
</hibernate-mapping>

【问题讨论】:

  • 线程“主”org.hibernate.MappingNotFoundException 中的异常:资源:在 org.hibernate 的 org.hibernate.cfg.Configuration.addResource(Configuration.java:517) 中找不到 Product.hbm.xml .cfg.Configuration.parseMappingElement(Configuration.java:1511) 在 org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1479)
  • ^^^^ 这是它给出的错误。
  • 另外请查看我添加的截图。
  • 两个 xml 应该在 WEB-INF 文件夹下的相同位置。或者给出特定的 Product.hbm.xml 位置。例如
  • 两个 xml 都在同一个文件夹“str”中。我根据给定步骤创建的这个项目:java4s.com/hibernate/hibernate-hello-world-program-in-eclipse

标签: eclipse hibernate configuration mapping


【解决方案1】:

您是否尝试过: 默认情况下,你的类路径是 src,所以 hibernate 可能会在 src 中搜索你的映射文件

【讨论】:

  • 是的,我这样做了......然后它给出了这个错误->线程“main”中的异常 org.hibernate.InvalidMappingException:无法从资源 str/Product.hbm.xml 解析映射文档跨度>
  • 线程“主”org.hibernate.MappingNotFoundException 中的异常:资源:/str/Product.hbm.xml 未找到
  • 如果你有一个 invalidMappingException hibernate 找到你的文档但没有解析它,所以 str/Product.hbm.xml 是好的路径,现在你在 hbm 文件中有一个解析错误你能提供它吗?
  • 还要提供你完整的mappingException的stacktrace,上面要注明原因。
  • thanx @all 但仍然给出错误。线程“main”中的异常 org.hibernate.InvalidMappingException:无法从资源 product.hbm.xml 解析映射文档,原因:org.hibernate.MappingException:查找属性时找不到类产品:productId, ,,,引起:java.lang.ClassNotFoundException: Product
猜你喜欢
  • 2017-10-06
  • 1970-01-01
  • 2015-07-19
  • 2020-11-18
  • 1970-01-01
  • 2014-11-19
  • 1970-01-01
  • 2012-04-11
  • 1970-01-01
相关资源
最近更新 更多