简体   繁体   中英

Error connecting to db with jboss tools / hibernate configuration

I'm attempting to use jboss tools hibernate code generation to generate DAOs and hibernate mappings for tables in my postgresql db. I have set-up my hibernate configuration but when I try to connect I get this error:

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)

I've looked inside StandardBasicTypes at line 54, which reads public static final BooleanType BOOLEAN = BooleanType.INSTANCE; and I've followed the field BooleanType.INSTANCE that does exist in class BooleanType.

I'm using hibernate-core-4.1.8.Final.jar, hibernate-spatial-4.0-M1.jar, and in my hibernate configuration, "Hibernate Version" is "4.0".

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

The problem had to do with my hibernate configuration, specifically the driver and dialect. Originally, I had

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

And I was receiving the error stack trace in the question above. I changed these properties to

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

And was able to connect to the db through hibernate tools. If anyone cares, I created a JIRA here to track the issue should anyone want to be able to use hibernate tools with geospatial objects.

Apparently all of your Hibernate jars and it's configuration in the editor need to match. Geofflittle's answer is spot on only if you make sure that your hibernate-spatial + hibernate-core + hibernate version selection in the editor drop-down are all at the same version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM