在IntelliJ Hibernate控制台中运行查询时MappingNotFoundException [英] MappingNotFoundException when running queries in IntelliJ Hibernate console

查看:136
本文介绍了在IntelliJ Hibernate控制台中运行查询时MappingNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在IntelliJ的Hibernate控制台中运行HQL查询。我已经将数据源添加到数据源视图中,并将我的 hibernate.cfg.xml 添加到Hibernate方面,以便显示在持久性视图中。 hibernate.cfg.xml 的内容是:

 < xml version ='1.0'encoding ='utf-8'?> 
<!DOCTYPE hibernate-configuration PUBLIC
- // Hibernate / Hibernate配置DTD // EN
http://hibernate.sourceforge.net/hibernate-configuration-3.0。 DTD>
< hibernate-configuration>
< session-factory>
< property name =connection.url> jdbc:mysql:// localhost / mmanager< / property>
< property name =connection.driver_class> com.mysql.jdbc.Driver< / property>
< property name =connection.username> root< / property>
< property name =connection.password>密码< / property>
< property name =dialect> com.puca.core.util.db.MySQLInnoDBDialect< / property>

<! - 映射文件 - >
< mapping resource =com / puca / messagemanager / api / model / XmlApiDlrMapping.hbm.xml/>
< / session-factory>
< / hibernate-configuration>

.hbm.xml 显示于绿色,而如果我将其更改为不存在的文件,则会显示为红色,因此IntelliJ似乎可以找到它。但是,如果我在运行像控制台的简单查询:

 从XmlApiDlrMapping xmlApiDlrMapping 
其中xmlApiDlrMapping.retries = 5

我收到错误消息:

 了java.lang.RuntimeException:org.hibernate.MappingNotFoundException:资源:COM /普卡/给messageManager /未找到API /模型/ XmlApiDlrMapping.hbm.xml在org.hibernate.cfg 
。 Configuration.addResource(Configuration.java:563)
在org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
在org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:在org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534 1555)

在org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
。在组织.hibernate.cfg.Configuration.configure(Configuration.java:1462)

我使用IntelliJ 10.5 .4。

解决方案

I这正是它在错误信息中所说的。映射XML文件丢失:



com / puca / messagemanager / api / model / XmlApiDlrMapping.hbm.xml



这些文件用于将表列映射到您的实体类字段。

http://docs.jboss.org/hibernate/orm /3.3/reference/en/html/tutorial.html#tutorial-firstapp-mapping


I'm trying to run HQL queries in IntelliJ's Hibernate Console. I've added the datasource to the Data Sources view and added my hibernate.cfg.xml to the Hibernate facet such that in appears in the Persistence view. The content of hibernate.cfg.xml is:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="connection.url">jdbc:mysql://localhost/mmanager</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.username">root</property>
        <property name="connection.password">password</property>
        <property name="dialect">com.puca.core.util.db.MySQLInnoDBDialect</property>

        <!-- mapping files -->
        <mapping resource="com/puca/messagemanager/api/model/XmlApiDlrMapping.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

The .hbm.xml is shown in green, whereas if I change it to a file that doesn't exist it is shown in red, so it seems that IntelliJ can find it. However, if I run a simple query in the console like:

from XmlApiDlrMapping xmlApiDlrMapping 
where xmlApiDlrMapping.retries = 5

I get an error:

java.lang.RuntimeException: org.hibernate.MappingNotFoundException: resource: com/puca/messagemanager/api/model/XmlApiDlrMapping.hbm.xml not found
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:563)
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)

I'm using IntelliJ 10.5.4.

解决方案

It's exactly what it says in the error message. The mapping XML file is missing:

com/puca/messagemanager/api/model/XmlApiDlrMapping.hbm.xml

These files are used to map table columns to your entity class fields.

http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/tutorial.html#tutorial-firstapp-mapping

这篇关于在IntelliJ Hibernate控制台中运行查询时MappingNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆