Groovy Griffon与Hibernate4插件类未找到异常

时间:2012-11-20 06:11:15

标签: groovy griffon hibernate-4.x

我一直在寻找一种快速简便的方法来编写一个非常跨平台的桌面应用程序。这让我想到JVM就是这样的地方。由于Groovy(Grails)在我的工作场所使用,我想我会尝试Griffon,因为他们声称它基本上是Grails用于桌面。

我想要一个持久性管理层,并且看起来GORM在这种环境中没有准备好showtime,所以我使用Hiffnate4插件为Griffon转向了hibernate。

并不是说我一般都使用过Hibernate,但我相信,根据指南,我正在做正确的事情。我的聚会表明这不支持连接类的注释,所以我使用的是hbm.xml文件。

插件提供的sample并不复杂,但我不明白我在哪里偏离。

这是一个示例类文件:

package gwash

import groovy.beans.Bindable

class DeliveryMethodModel {
   // @Bindable String propName
}

以下是一些堆栈跟踪:

org.hibernate.InvalidMappingException: Could not parse mapping document from res
ource gwash\DeliveryMethod.hbm.xml
        at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Con
figuration.java:3415)
        at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXmlQueu
e(Configuration.java:3404)
        at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(C
onfiguration.java:3392)
        at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:
1341)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.jav
a:1737)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.jav
a:1788)
        at org.hibernate.cfg.Configuration$buildSessionFactory.call(Unknown Sour
ce)
        at griffon.plugins.hibernate4.Hibernate4Connector.connect(Hibernate4Conn
ector.groovy:72)
        at griffon.plugins.hibernate4.Hibernate4Connector.connect(Hibernate4Conn
ector.groovy)
        at griffon.plugins.hibernate4.Hibernate4Connector$connect.call(Unknown S
ource)
        at Hibernate4GriffonAddon.addonInit(Hibernate4GriffonAddon.groovy:27)
        at griffon.core.GriffonAddon$addonInit.call(Unknown Source)
        at griffon.core.GriffonAddon$addonInit.call(Unknown Source)
        at org.codehaus.griffon.runtime.util.AddonHelper.handleAddon(AddonHelper
.groovy:155)
        at org.codehaus.griffon.runtime.util.AddonHelper.handleAddonsAtStartup(A
ddonHelper.groovy:105)
        at org.codehaus.griffon.runtime.core.DefaultAddonManager.doInitialize(De
faultAddonManager.java:33)
        at org.codehaus.griffon.runtime.core.AbstractAddonManager.initialize(Abs
tractAddonManager.java:101)
        at org.codehaus.griffon.runtime.util.GriffonApplicationHelper.initialize
AddonManager(GriffonApplicationHelper.java:320)
        at org.codehaus.griffon.runtime.util.GriffonApplicationHelper.prepare(Gr
iffonApplicationHelper.java:123)
        at org.codehaus.griffon.runtime.core.AbstractGriffonApplication.initiali
ze(AbstractGriffonApplication.java:221)
        at griffon.swing.AbstractSwingGriffonApplication.bootstrap(AbstractSwing
GriffonApplication.java:74)
        at griffon.swing.AbstractSwingGriffonApplication.run(AbstractSwingGriffo
nApplication.java:131)
        at griffon.swing.SwingApplication.main(SwingApplication.java:36)
Caused by: org.hibernate.PropertyNotFoundException: field [id] not found on gwas
h.DeliveryMethodModel
        at org.hibernate.property.DirectPropertyAccessor.getField(DirectProperty
Accessor.java:182)
        at org.hibernate.property.DirectPropertyAccessor.getField(DirectProperty
Accessor.java:189)
        at org.hibernate.property.DirectPropertyAccessor.getField(DirectProperty
Accessor.java:189)
        at org.hibernate.property.DirectPropertyAccessor.getField(DirectProperty
Accessor.java:189)
        at org.hibernate.property.DirectPropertyAccessor.getField(DirectProperty
Accessor.java:189)
        at org.hibernate.property.DirectPropertyAccessor.getField(DirectProperty
Accessor.java:174)
        at org.hibernate.property.DirectPropertyAccessor.getGetter(DirectPropert
yAccessor.java:197)
        at org.hibernate.internal.util.ReflectHelper.getter(ReflectHelper.java:2
53)
        at org.hibernate.internal.util.ReflectHelper.reflectedPropertyClass(Refl
ectHelper.java:229)
        at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.
java:326)
        at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:449)
        at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBi
nder.java:382)
        at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:322)
        at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:173)
        at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Con

我的xml映射文件:

<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="gwash">
    <class name="DeliveryMethodModel" table="[DELIVERY METHODS]">
        <id name="id" column="[DELIVERY METHOD ID]">
            <generator class="increment"/>
        </id>
        <property name="method" column="[DELIVERY METHOD]"/>
    </class>
</hibernate-mapping>
编辑:我已按照指示移除了括号和空格。在数据库端将DataSource.groovy更改为“create”。仍然遇到同样的问题。 hibernate与griffon / hsqldb / groovy集成的例子很少详细。我是否需要为模型文件创建所有给定属性才能正确解析?我从未使用过hibernate。也不常客。也不是格里芬。如果我能解决这个问题,我肯定会为社区提供反馈,如果不是,我会自己动手做ORM,因为这是一个相当小的项目。而不是让我自己。

1 个答案:

答案 0 :(得分:3)

你实际上是否用[]包裹了字符串?

我怀疑对于定义为

的类
package gwash
import groovy.beans.Bindable
class DeliveryMethodModel {
    Long id
    @Bindable String method
}

映射文件将是

<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="gwash">
    <class name="DeliveryMethodModel" table="DELIVERY_METHODS">
        <id name="id" column="DELIVERY_METHOD_ID">
            <generator class="increment"/>
        </id>
        <property name="method" column="DELIVERY_METHOD"/>
    </class>
</hibernate-mapping>