为什么HibernateDaoSupport没有启用hibernate过滤器。我正在尝试在我的代码中启用过滤器但是没有启用。我已经发布了spring和xml配置文件,如下所示。我提供了所有文件。
EmployeeHibernateDao.java:
public class EmployeeHibernateDao extends HibernateDaoSupport {
public void saveDetails(Student s){
getSession().merge(s);
}
public void getDetails(){
Criteria ct= getSession().createCriteria(Student.class);
getSession().enableFilter("addressFilter");
List<Student> list = ct.list();
for(Student s: list){
System.out.println(s.getSname());
}
}
}
student.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.spring.hibernatedao.Student" table="student24">
<composite-id class="com.spring.hibernatedao.Address" name="address">
<key-property name="addressNo" column="addressno" />
<key-property name="addressName" column="addressname" />
</composite-id>
<property name="sname" column="sname" />
<property name="date" column="inserteddate" />
<filter name="addressFilter" condition="sname = 'hello'" />
</class>
<filter-def name="addressFilter" />
</hibernate-mapping>
的applicationContext.xml:
<beans>
<bean id="datasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@localhost:1521:xe" />
<property name="username" value="system" />
<property name="password" value="system" />
</bean>
<bean id="myssessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="datasource" />
<property name="mappingResources">
<list>
<value>/com/spring/hibernatedao/student.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
</props>
</property>
</bean>
<bean id="empdao" class="com.spring.hibernatedao.EmployeeHibernateDao">
<property name="sessionFactory" ref="myssessionFactory" />
</bean>
Test.java:
public class Test {
public static void main(String[] args) {
ApplicationContext ct=new ClassPathXmlApplicationContext("com/spring/hibernatedao/applicationContext.xml");
EmployeeHibernateDao empdao= ct.getBean("empdao", EmployeeHibernateDao.class);
empdao.getDetails();
}
}
答案 0 :(得分:0)
将以下配置添加到student.xml中并尝试:
<filter name="addressFilter" condition="sname = :addressFilterParam" />
</class>
<filter-def name="addressFilter">
<filter-param name="addressFilterParam" type="java.lang.String"/>
</filter-def>