1

我正在尝试在 IntelliJ 的休眠控制台中运行 HQL 查询。我已将数据源添加到 Data Sources 视图,并将 my 添加hibernate.cfg.xml到 Hibernate facet,这样 in 就会出现在 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。

4

1 回答 1

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

于 2012-04-24T08:33:54.287 回答