所以,我的问题是:我所有的项目都(嗯?)配置但我没有延迟加载!
这是我正在制作的示例项目,以准备紧随其后的真实项目。简而言之,我有 3 个表:类别、产品、客户,以及最后两个之间的关联,即购买。
在 Flex 方面,我有两个简单的数据网格,第一个包含产品,第二个包含与所选产品关联的客户端。在服务器端,一个 Spring-BlazeDS-Integration 架构和一个检索所有产品的服务。
我的配置文件:web.xml
enter code here
<web-app>
<display-name>Spring BlazeDS Integration</display-name>
<description>Spring BlazeDS Integration</description>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/applicationContext.xml</param-value>
</context-param>
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>flushMode</param-name>
<param-value>ALWAYS</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>/messagebroker/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>Spring MVC Servlet Dispatcher</servlet-name>
<display-name>Spring MVC Servlet Dispatcher</display-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/webApplicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>RDSDispatchServlet</servlet-name>
<servlet-class>flex.rds.server.servlet.FrontEndServlet</servlet-class>
<init-param>
<param-name>messageBrokerId</param-name>
<param-value>_messageBroker</param-value>
</init-param>
<init-param>
<param-name>useAppserverSecurity</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>10</load-on-startup>
</servlet>
<servlet-mapping id="RDS_DISPATCH_MAPPING">
<servlet-name>RDSDispatchServlet</servlet-name>
<url-pattern>/CFIDE/main/ide.cfm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Spring MVC Servlet Dispatcher</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
</web-app>
应用程序上下文.xml
<beans xmlns="..">
<bean id="transactionProxy" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="txManager" />
<property name="transactionAttributes">
<props>
<prop key="create*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="mappingResources">
<list>
<value>tuto/Product.hbm.xml</value>
<value>tuto/Client.hbm.xml</value>
<value>tuto/Category.hbm.xml</value>
<value>tuto/Buy.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="dataSource"><ref bean="dataSource"/></property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/tuto" />
<property name="username" value="root" />
</bean>
</beans>
webApplicationContext.xml
<beans xmlns=".....">
<bean id="hibernate-lazy-adapter" class="org.springframework.flex.core.ManageableComponentFactoryBean">
<constructor-arg value="net.digitalprimates.persistence.hibernate.HibernateAdapter"/>
<property name="properties">
<value>
{
"hibernate": {
"sessionFactory": {"class":"net.digitalprimates.persistence.hibernate.utils.SpringSessionUtil", "getCurrentSessionMethod":"getCurrentSession"
}, "loadMethod":"load"
}
}
</value>
</property>
</bean>
<flex:message-broker>
<flex:remoting-service default-adapter-id="hibernate-lazy-adapter" default-channels="my-amf" />
</flex:message-broker>
<bean id="productService" parent="transactionProxy">
<property name="target">
<bean class="tuto.ServiceProductImpl">
<property name="productDAO"><ref bean="productDAO"/></property>
</bean>
</property>
<flex:remoting-destination/>
</bean>
<bean id="productDAO" class="tuto.DAOProductHibernate" lazy-init="default">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</beans>
产品.hbm.xml
<hibernate-mapping package="tuto">
<class name="Product" table="product">
<id name="productId" type="long" column="product_id">
<generator class="increment"/>
</id>
<property name="name" column="name" type="string" not-null="true" length="40"/>
<many-to-one name="category" column="category_id" class="Category" not-null="true" lazy="false">
</many-to-one>
<set name="clients" table="buy" cascade="delete">
<key column="product_id"/>
<many-to-many column="client_id" class="Client"/>
</set>
</class>
</hibernate-mapping>
这是 ProductDAO.java 中的代码
public Collection<Product> findAll() {
Session session = SessionFactoryUtils.getSession(getSessionFactory(), false);
try {
return session.createQuery("from Product").list();
} catch (HibernateException e) {
throw SessionFactoryUtils.convertHibernateAccessException(e);
}
}
如果您需要更多信息来帮助,请询问,我只是不想在第一条消息中发布太多代码:)
如您所见,我只是从数据库中检索产品,但是当我在数据网格中选择产品时,会填充客户端的数据网格,因此也会加载客户端!另外,我有一个日志跟踪,我可以看到 Product 表上有多个请求,Client 表上也有多个请求。在我看来,只有一个应该在这里!不 ?!
我在等你的建议,非常感谢!
阿尔诺。