Presentation is loading. Please wait.

Presentation is loading. Please wait.

Corso di “Sviluppo di applicazioni Web”

Similar presentations


Presentation on theme: "Corso di “Sviluppo di applicazioni Web”"— Presentation transcript:

1 Corso di “Sviluppo di applicazioni Web”
Docente: Giovanni Grasso - Hibernate and GWT integration

2 Spring WebApplicationContext
Spring ApplicationContext can be loaded declaratively within the context of an application server. J2EE standard provides mechanism for defining context parameters and application listeners in the Web deployment descriptor file (web.xml). <context-param> <param-name> contextConfigLocation </param-name> <param-value> /WEB-INF/applicationContext.xml </param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener>

3 Hibernate + GWT …. problems
Hibernate POJO are not real POJO. The persistence library adds a lot of needed information, such as session factory, by creating a dynamic proxy (with CGLIB or Javassist) around your instance. When you manipulate an Hibernate POJO, you do not do it with an instance of your class GWT can only serialize (to Javascript) only a subset of the JRE (basically, the java.lang and the java.util packages). Hibernate defines its own implementation of the Java collections (PersistentList, PersistentSet and PersistentMap), of course not supported by GWT serialization process.

4 hibernate4gwt hibernate4gwt permits you to use your Hibernate POJO (and especiallay the partially loaded ones) in the GWT client side code without pain. hibernate4gwt allows different configurations, depending on your needs and constraints. stateless mode (the default) : your server remains stateless and do not store any extra information. Your domain classes will have to inherit from LazyPojo to store lazy attributes.

5 Hibernate4gwt - How to Download the hibernate4gwt distribution. All the dependency libraries are included in the "lib" directory (link) Edit your gwt xml file to inherit from hibernate4gwt and declare the domain package <inherits name='net.sf.hibernate4gwt.Hibernate4Gwt15'/> <inherits name='net.sf.hibernate4gwt.emul.java5.ejb3.Ejb3'/> <source path='domain'/> All domain classes inherit from “net.sf.hibernate4gwt.pojo.java5.LazyPojo” public class User extends LazyPojo

6 Hibernate4gwt - How to HibernateBeanManager initialisation
applicationContext.xml <bean id="hibernateBeanManager“ class="net.sf.hibernate4gwt.core.HibernateBeanManager">   <property name="sessionFactory" ref="sessionFactory" /> </bean> RemoteService Just make your RemoteService implementation inherits from the HibernateRemoteService instead public class UserRemoteImpl extends HibernateRemoteService implements UserRemote

7 Hibernate4gwt - lazy properties
Lazy associations are not loaded by Hibernate/JPA Hibernate4GWT replaces it with null. In DAO methods explicitly call the XXX getter on server-side (to force association loading) or change your query to "from MyItem as item inner join fetch item.xxx …”


Download ppt "Corso di “Sviluppo di applicazioni Web”"

Similar presentations


Ads by Google