使用jboss tools / hibernate配置连接到db时出错

时间:2014-01-27 18:34:46

标签: java hibernate postgresql jboss postgis

我正在尝试使用jboss工具hibernate代码生成来为我的postgresql db中的表生成DAO和hibernate映射。我已经设置了我的hibernate配置,但是当我尝试连接时,我收到此错误:

java.lang.NoSuchFieldError: INSTANCE
    at org.hibernate.type.StandardBasicTypes.<clinit>(StandardBasicTypes.java:54)
    at org.hibernate.spatial.dialect.postgis.PostgisDialect.registerTypesAndFunctions(PostgisDialect.java:55)
    at org.hibernate.spatial.dialect.postgis.PostgisDialect.<init>(PostgisDialect.java:42)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at org.hibernate.dialect.resolver.DialectFactory.constructDialect(DialectFactory.java:157)
    at org.hibernate.dialect.resolver.DialectFactory.buildDialect(DialectFactory.java:109)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:146)
    at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2163)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2155)
    at org.hibernate.console.ConsoleConfiguration$6.execute(ConsoleConfiguration.java:430)
    at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63)
    at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:107)
    at org.hibernate.console.ConsoleConfiguration.getSettings(ConsoleConfiguration.java:428)
    at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter$2.execute(LazyDatabaseSchemaWorkbenchAdapter.java:119)
    at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63)
    at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:107)
    at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter.readDatabaseSchema(LazyDatabaseSchemaWorkbenchAdapter.java:115)
    at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter.getChildren(LazyDatabaseSchemaWorkbenchAdapter.java:65)
    at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:106)
    at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:235)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

我查看了第54行的StandardBasicTypes,它读取了public static final BooleanType BOOLEAN = BooleanType.INSTANCE;,并且我遵循了BooleanType类中确实存在的BooleanType.INSTANCE字段。

我正在使用hibernate-core-4.1.8.Final.jar,hibernate-spatial-4.0-M1.jar,在我的hibernate配置中,“Hibernate Version”是“4.0”。

3 个答案:

答案 0 :(得分:0)

检查你的类路径上是否没有两个休眠版本

答案 1 :(得分:0)

问题与我的hibernate配置有关,特别是驱动程序和方言。最初,我有

<property name="hibernate.connection.driver_class">org.postgis.DriverWrapper</property>
<property name="hibernate.dialect">org.hibernate.spatial.dialect.postgis.PostgisDialect</property>

我在上面的问题中收到错误堆栈跟踪。我将这些属性更改为

<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>

并且能够通过hibernate工具连接到db。如果有人关心,我创建了一个JIRA here来跟踪问题,如果有人希望能够将hibernate工具与地理空间对象一起使用。

答案 2 :(得分:0)

显然,您的所有Hibernate jar和它在编辑器中的配置都需要匹配。仅当您确保在编辑器下拉列表中选择的休眠空间+休眠核心+休眠版本都为同一版本时,Geofflittle的答案才对。