-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4333115
By: bhluo
Hi,Everyone, When I develope my application in zk 2.3.1 + spring 2 + Hibernate
3.2 ,that I find data is successful,but I insert one record ,log files is no error information,no record in mysql,data no commit.I don't know where error is occur.if same spring config,I develope my application is successful in JSF
+ SPRING 2.0 + Hibernate 3.2
if have question,Please email it to me,my email [email protected]. thanks!
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4333150
By: sousa1981
I dont understandy what do you want? do you want help?
I have successful integrated ZK 2.x.x + Spring 2 + Hibernate 3.2 Annotation and HBM with no problem.
Regards,
Marcos de Sousa
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4333654
By: sdswamy
I have integrated 2.3.1 with Spring 2.0.3 and Hibernate 3.2 and JPA annotations.
No problems. I used appfuse 2.0 for the integration. I just deleted out all the JSF/Struts/Spring MVC out and started developing the front-end with ZK.
It would be really nice to have a ZK archetype for Appfuse. I have posted it under feature requests.
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4334069
By: bhluo
hi,Marcos de Sousa:
May you send it (web.xml,context.xml,zk.xml) to me? I Want to know that i config file ( spring ,hibernate,zk) is right. thanks!
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4334952
By: henrichen
Hi Marcos de Sousa,
Can you post that to ZK's How-to (wiki) so the community can share it :-).
Thanks.
/henri
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4335049
By: sousa1981
Until Friday I will post an complete example on ZK's How-to (wiki), showing an integration between ZK 2.x.x + Spring 2 + Hibernate 3.2 Annotation
Then I will post ZK 2.x.x + Spring 2 + Hibernate 3.2 Annotation + OSWORKFLOW complete configuration.
But for now let me send to you same help:
-------------CONTEXT.XML--------------
<?xml version="1.0" encoding="UTF-8"?>
<Context crossContext="true" reloadable="true">
<Resource name="DefaultDS" auth="Container"
type="javax.sql.DataSource"
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://COMPUTERNAME:1433;DatabaseName=SGC"
username="YOUR_USERNAME" password="YOUR_PASSWORD" maxActive="5" maxIdle="5"
maxWait="-1" />
</Context>
--------------------------------------
-------------WEB.XML--------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<description>
<![CDATA[SGC]]>
</description>
<display-name>SGC</display-name>
<!-- Spring ApplicationContext -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/spring-*.xml</param-value>
</context-param>
<!-- INI ZK -->
<!-- INI DSP -->
<servlet>
<description>
<![CDATA[The servlet loads the DSP pages.]]>
</description>
<servlet-name>dspLoader</servlet-name>
<servlet-class>
org.zkoss.web.servlet.dsp.InterpreterServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dspLoader</servlet-name>
<url-pattern>*.dsp</url-pattern>
</servlet-mapping>
<!-- END DSP -->
<servlet>
<description>ZK loader for ZUML pages</description>
<servlet-name>zkLoader</servlet-name>
<servlet-class>
org.zkoss.zk.ui.http.DHtmlLayoutServlet
</servlet-class>
<init-param>
<param-name>update-uri</param-name>
<param-value>/zkau</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zul</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>/zk/*</url-pattern>
</servlet-mapping>
<servlet>
<description>The asynchronous update engine for ZK</description>
<servlet-name>auEngine</servlet-name>
<servlet-class>
org.zkoss.zk.au.http.DHtmlUpdateServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>auEngine</servlet-name>
<url-pattern>/zkau/*</url-pattern>
</servlet-mapping>
<!-- END ZK -->
<listener>
<description>
Used to cleanup when a session is destroyed
</description>
<display-name>ZK Session Cleaner</display-name>
<listener-class>
org.zkoss.zk.ui.http.HttpSessionListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<!-- COMMENT IT IF NOT USING ACEGI SECURITY
<listener>
<listener-class>
org.zkoss.zkplus.acegi.AcegiSecurityContextListener
</listener-class>
</listener>
<filter>
<filter-name>Acegi Filter Chain Proxy</filter-name>
<filter-class>
org.acegisecurity.util.FilterToBeanProxy
</filter-class>
<init-param>
<param-name>targetBean</param-name>
<param-value>filterChainProxy</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Acegi Filter Chain Proxy</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-->
<!-- Hibernate OpenSession Filter -->
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sessionFactory</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>*.zul</url-pattern>
</filter-mapping>
<!-- Fim filter -->
<!-- Miscellaneous -->
<session-config>
<session-timeout>10</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.zul</welcome-file>
</welcome-file-list>
<!-- FORCE USING SSL OR HTTPS -->
<!-- <security-constraint>
<web-resource-collection>
<web-resource-name>sousa1981</web-resource-name>
<description>Acesso so via HTTPS</description>
<url-pattern>/*</url-pattern>
<http-method>POST</http-method>
<http-method>GET</http-method>
</web-resource-collection>
<user-data-constraint>
<description>Usar SSL</description>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>-->
<!-- INI resource-ref -->
<resource-ref>
<description>DefaultDS</description>
<res-ref-name>jdbc/DefaultDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<!-- END resource-ref -->
</web-app>
--------------------------------------
-------------ZK.XML--------------
NEED NOTHING
--------------------------------------
-------------SPRING-JNDI.XML--------------
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.0.xsd">
<!-- JNDI DataSource for J2EE environments -->
<jee:jndi-lookup id="dataSource"
jndi-name="java:comp/env/DefaultDS" />
</beans>
--------------------------------------
-------------SPRING-SQL.XML--------------
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryB
ean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.nemex.sgc.persistence.Menu</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="daoTxTemplate" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean
">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="menuDao" parent="daoTxTemplate">
<property name="proxyInterfaces">
<list>
<value>com.nemex.sgc.persistence.dao.MenuDao</value>
</list>
</property>
<property name="target">
<bean class="com.nemex.sgc.persistence.dao.MenuDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</property>
</bean>
<bean id="menuManager" parent="daoTxTemplate">
<property name="proxyInterfaces">
<list>
<value>
com.nemex.sgc.persistence.manager.MenuManager
</value>
</list>
</property>
<property name="target">
<bean
class="com.nemex.sgc.persistence.manager.MenuManagerImpl">
<property name="menuDao" ref="menuDao" />
</bean>
</property>
</bean>
</beans>
--------------------------------------
-------------CREATE TABLE MENU-------------- create table Menu (
id numeric(18, 0) identity(1,1),
nome varchar(255) UNIQUE NOT NULL,
url varchar(255),
situacao int default 1,
primary key (id)
);
--------------------------------------
-------------Menu.java--------------
package com.nemex.sgc.persistence;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.OneToMany;
@Entity
public class Menu {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String nome;
private String url;
private Integer situacao;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "menu")
private Set<SubMenu> submenus = new HashSet<SubMenu>();
public Menu() {
}
//getters and setters
--------------------------------------
--------------------------------------
Make your DAO and your MANAGER
--------------------------------------
Regards,
Marcos de Sousa
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4335664
By: bhluo
My Spring config file:
context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="DataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/smt</value>
</property>
<property name="username">
<value>smt</value>
</property>
<property name="password">
<value>smt</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="mappingLocations">
<list>
<value>/WEB-INF/AppUser.hbm.xml</value>
<value>/WEB-INF/SmtItemMaintainV.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.use_outer_join">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</prop>
</props>
</property>
<property name="dataSource">
<ref bean="DataSource" />
</property>
</bean>
<bean class="org.smtapp.dao.AppUserDao" id="UsersDao">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean class="org.smtapp.service.AppUserService"
id="AppUserService">
<property name="aud">
<ref local="UsersDao" />
</property>
</bean>
<bean
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
id="transactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="matchAllMethods"
class="org.springframework.transaction.interceptor.MatchAlwaysTransactionAttri
buteSource" />
<bean
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean
"
id="UserService">
<property name="transactionManager">
<ref local="transactionManager" />
</property>
<property name="target">
<ref local="AppUserService" />
</property>
<property name="transactionAttributeSource">
<ref bean="matchAllMethods" />
</property>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="jdbcTemplate"
class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg>
<ref bean="DataSource" />
</constructor-arg>
</bean>
<bean id="ud" class="org.smtapp.dao.userDao">
<property name="jdbcTemplate">
<ref bean="jdbcTemplate" />
</property>
</bean>
<bean class="org.smtapp.service.userservice" id="user">
<property name="udao">
<ref local="ud" />
</property>
</bean>
</beans>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>
zk-food-to-go</display-name>
<welcome-file-list>
<welcome-file>appuser.zul</welcome-file>
<welcome-file>index.zul</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- SECTION FOR SPRING -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/context.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- ZK -->
<listener>
<description>Used to cleanup when a session is destroyed</description>
<display-name>ZK Session Cleaner</display-name>
<listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
</listener>
<servlet>
<description>ZK loader for ZUML pages</description>
<servlet-name>zkLoader</servlet-name>
<servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
<!-- Must. Specifies URI of the update engine (DHtmlUpdateServlet).
It must be the same as <url-pattern> for the update engine.
-->
<init-param>
<param-name>update-uri</param-name>
<param-value>/zkau</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zul</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zhtml</url-pattern>
</servlet-mapping>
<!-- Optional. Uncomment it if you want to use richlets.
-->
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>/zk/*</url-pattern>
</servlet-mapping>
<servlet>
<description>The asynchronous update engine for ZK</description>
<servlet-name>auEngine</servlet-name>
<servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>auEngine</servlet-name>
<url-pattern>/zkau/*</url-pattern>
</servlet-mapping>
<!-- Uncomment if you want to use the ZK filter
<filter>
<filter-name>zkFilter</filter-name>
<filter-class>org.zkoss.zk.ui.http.DHtmlLayoutFilter</filter-class>
<init-param>
<param-name>extension</param-name>
<param-value>html</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>zkFilter</filter-name>
<url-pattern>/test/special.jsp</url-pattern>
</filter-mapping>
-->
<!-- //// -->
</web-app>
zk.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- zk.xml
Purpose:
Description:
History:
Sun Mar 26 16:29:07 2006, Created by [email protected]
Copyright (C) 2006 Potix Corporation. All Rights Reserved.
-->
<zk>
<!--
<log>
<description>[Optional] Monitor i3-log.conf and register a handler for the specified log-base</description>
<log-base></log-base>
</log>
-->
<!--
<language-config>
<addon-uri>/WEB-INF/lang-addon.xml</addon-uri>
</language-config>
-->
<!-- Turn on the following if you want to keep session after Web server restarts
<system-config>
<ui-factory-class>org.zkoss.zk.ui.http.SerializableUiFactory</ui-factory-class
>
</system-config>
-->
<!-- Turn on the following if used with WebLogic 9.1
<system-config>
<cache-provider-class>org.zkoss.zk.ui.sys.GlobalDesktopCacheProvider</cache-pr
ovider-class>
</system-config>
-->
<!-- Optional -->
<session-config>
<timeout-uri>/timeout.zul</timeout-uri>
<!-- An empty URL can cause the browser to reload the same URL
<timeout-uri></timeout-uri>
-->
</session-config>
<!-- Optional -->
<listener>
<description>[Optional] Mointor the statistic</description>
<listener-class>org.zkoss.zk.ui.util.Statistic</listener-class>
</listener>
<!-- Used for test desktop.zul
<listener>
<listener-class>org.zkoss.zkdemo.test.ComponentPools$Init</listener-class>
</listener>
-->
<!-- Configure the error page
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/WEB-INF/sys/error.zul</location>
</error-page>
-->
<!-- Any number of preferences.
<preference>
<name></name>
<value></value>
</preference>
-->
<!-- Configure the Hibernate SessionFactory Lifecycle. -->
<listener>
<description>Hibernate SessionFactory Lifecycle</description>
<listener-class>org.zkoss.zkplus.hibernate.HibernateSessionFactoryListener</li
stener-class>
</listener>
<!-- Configure the Hibernate "Open Session In View" Session Lifecycle -->
<listener>
<description>Hibernate "Open Session In View" Session Lifecycle</description>
<listener-class>org.zkoss.zkplus.hibernate.OpenSessionInViewListener</listener
-class>
</listener>
<!-- Hibernate thread session context handler -->
<listener>
<description>Hibernate thread session context handler</description>
<listener-class>
org.zkoss.zkplus.hibernate.HibernateSessionContextListener
</listener-class>
</listener>
-->
</zk>
Please Marcos de Sousa help me to check it!
thanks.
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4337676
By: sousa1981
I was out of office,
I will check it soon as possible.
On friday I will post a wiki integration Spring + Hibernate + ZK.
Regards,
Marcos de Sousa
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4338301
By: tkohalmi
bhluo,
I thought the following should be in the web.xml file.
<!-- Configure the Hibernate "Open Session In View" Session Lifecycle --> <listener> <description>Hibernate "Open Session In View" Session Lifecycle</description> <listener-class>org.zkoss.zkplus.hibernate.OpenSessionInViewListener</listener-class>
</listener>
By the way I am having the same exact problem using ZK 2.2.1, Spring 1.2.8 and Hibernate 3.
I can look up data without the lazyinitialization problem (after adding OpenSessionInViewFilter to web.xml and SpringTransactionSynchronizationListener
to zk.xml), but I cannot commit a thing. No failure, no error message it is just that nothing gets saved. It turns out that it may have something to do with the OpenSessionInViewFilter setting FlushMode to NEVER coupled with the sessionFactory boundaries not being recognised. FlushMode is not flipped to AUTO or ALWAYS to facilitate the commit.
So I end up calling my DAO methods to turn the Hibernate session to FlushMode.AUTO, force a flush() on the session, and flip back to FlushMode.NEVER. It is a really ugly workaround defeating the puprose of sessionFactory, but I have deadlines to make and need somthing working until this is resolved.
Peace,
tk
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4340598
By: sousa1981
Hi Henri,
I posted ZK's How-to (wiki)
http://en.wikibooks.org/wiki/ZK/How-Tos#ZK_2.x.x_.2B_Spring_2.x.x_.2B_Hibernate_
3.x_.2B_JUnit_Test
Regards,
Marcos de Sousa
Asked: 2007-05-28 07:58:30 +0800
Seen: 295 times
Last updated: Jun 02 '07