Hey. I'm using JBoss AS 4.2.2 GA with Portal 2.6.4 and running into problems 
with accessing objects in the view: 

"Caused by: org.hibernate.LazyInitializationException: could not initialize 
proxy - no Session"

I am using the HibernateService deployed as HAR to retrieve objects in the 
processAction-Method of the GenericPortlet. The configuration of the Service is 
as follows (jboss-service.xml):


  | <server>
  |     <mbean code="org.jboss.hibernate.jmx.Hibernate"
  |             name="ebal:name=SessionFactory">
  |             <attribute name="DatasourceName">java:/PortalDS</attribute>
  |             <attribute name="Dialect">
  |                     org.hibernate.dialect.MySQLDialect
  |             </attribute>
  |             <attribute name="SessionFactoryName">
  |                     java:/hibernate/SessionFactory
  |             </attribute>
  |             <attribute name="Hbm2ddlAuto">update</attribute>
  |             <attribute name="ShowSqlEnabled">true</attribute>
  |             <attribute name="ScanForMappingsEnabled">true</attribute>
  |     </mbean>
  | </server>
  | 

The service uses the standard PortalDS which is bound to a transaction:


  | <datasources>
  |   <local-tx-datasource>
  |     <jndi-name>PortalDS</jndi-name>
  |     
<connection-url>jdbc:mysql://localhost:3306/jbossportal?useServerPrepStmts=false</connection-url>
  |     <driver-class>org.gjt.mm.mysql.Driver</driver-class>
  |     <user-name></user-name>
  |     <password></password>
  |   </local-tx-datasource>
  | </datasources>
  | 

In the init()-Method of my Portlet I am retrieving the HibernateService:

  | public void init(javax.portlet.PortletConfig config)
  |                     throws PortletException {
  |             super.init(config);
  |             try {
  |                     InitialContext ctx = new InitialContext();
  |                     sessionFactory = (SessionFactory) ctx
  |                                     
.lookup("java:/hibernate/SessionFactory");
  |             } catch (NamingException e) {
  |                     throw new PortletException(e.getMessage());
  |             }
  |     };
  | 

and later in the processAction-Method I am retrieving some objects through 
sessionFactory.getCurrentSession() and store them in the PortalSession. This 
works fine for I retrieve the current session bound to the transaction. Btw, I 
have also included the transattribute in the jboss-portlet.xml:


  | <portlet>
  |             <portlet-name>TestPortlet</portlet-name>
  |             <trans-attribute>Required</trans-attribute>
  |     </portlet>
  | 

Everything works fine so far until I try to access properties from objects in 
the portletSession in the view (jsp, through jstl) which are proxied through 
hibernate (lazy initialized). The session is already closed in the view and so 
is the transaction. Normally I would set a HibernateSession filter in the 
web.xml and open/close the session before/after the request in a standard 
struts/spring mvc webapplication and have the session open in view but I fear 
this will not work in a portlet environment.

I did browse through this forum and the web all the day but did not come to a 
conclusion how to achieve to hold the session/transaction open (and closed 
after the entire request). 

Is there anyone who was running into the same problem? Maybe I miss something 
substantial because I could not find any solution to this very common problem? 
Is there a way to span the transaction around the view-rendering as well? Every 
help or hints are appreciated! 

Regards,
Eric

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4138913#4138913

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4138913
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to