我有以下hibernate查询:
@SuppressWarnings("unchecked")
@Override
public List<Admin> getAffectedAdmins(String wktFilter) {
WKTReader fromText = new WKTReader();
Geometry filter = null;
try {
filter = fromText.read(wktFilter);
System.out.println("Filter = " + filter);
} catch (ParseException e) {
e.printStackTrace();
}
hibernateTemplate = new HibernateTemplate(sessionFactory);
List<Admin> admins = new ArrayList<Admin>();
admins = (List<Admin>) hibernateTemplate.findByCriteria(
DetachedCriteria.forClass(Admin.class)
.add(SpatialRestrictions.intersects("geom", filter)));
return admins;
}
当我执行上述方法时,抛出以下异常:
java.lang.NoSuchMethodError: org.hibernate.criterion.CriteriaQuery.getFactory()Lorg/hibernate/engine/spi/SessionFactoryImplementor;
我的spring配置文件中的相关部分如下所示:
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
p:password="${jdbc.password}" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
我的环境:Hibernate-3.6.10.FINAL,Spring 3.1.2.RELEASE,Hibernate Spatial 4.x,PostGIS JDBC 1.5.2和PostgreSQL 8.4-702.jdbc3。
对我可能做错的任何想法都将受到高度赞赏。
更新:这适用于简单查询;不涉及空间数据的查询。所以,我猜它的空间成分有问题。
更新:pom.xml,我已将相关部分包含在我的POM文件中。
<properties>
<spring.version>3.1.2.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.10.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>4.0-M1</version>
</dependency>
<dependency>
<groupId>org.postgis</groupId>
<artifactId>postgis-jdbc</artifactId>
<version>${hibernate-spatial.version}</version>
<exclusions>
<exclusion>
<artifactId>postgis-jdbc</artifactId>
<groupId>org.postgis</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.postgis</groupId>
<artifactId>postgis-jdbc</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.6.10.Final</version>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>8.4-702.jdbc3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
答案 0 :(得分:0)
我的环境:Hibernate-3.6.10.FINAL,Hibernate Spatial 4.x
但是http://www.hibernatespatial.org/:
与Hibernate ORM的兼容性
Hibernate Spatial version 1.0 is compatible with Hibernate 3.2.x - 3.5.x
Hibernate Spatial version 1.1.x is compatible with Hibernate 3.6.x
Hibernate Spatial version 4.0 is compatible with Hibernate 4.x