我有以下休眠查询:
@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>