在IntelliJ Hibernate控制台中运行查询时,MappingNotFoundException

时间:2012-04-24 08:26:39

标签: java hibernate intellij-idea

我正在尝试在IntelliJ的Hibernate控制台中运行HQL查询。我已将数据源添加到Data Sources视图,并将我的hibernate.cfg.xml添加到Hibernate facet,以便在Persistence视图中显示。 hibernate.cfg.xml的内容是:

<?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>

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

from XmlApiDlrMapping xmlApiDlrMapping 
where xmlApiDlrMapping.retries = 5

我收到错误:

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)

我正在使用IntelliJ 10.5.4。

1 个答案:

答案 0 :(得分:0)

这正是它在错误消息中所说的内容。缺少映射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