[jboss-user] [JBoss Seam] - Simple application component

quilleashm do-not-reply at jboss.com
Thu Feb 1 08:27:13 EST 2007


Using Seam 1.1.0.GA

I have a simple Seam component which is just for injecting a singleton session factory and a ManagedHibernateSession that uses it. (I'm aware of the HibernateSessionFactory component but I think this problem is more general).

First the session factory wrapper component.


  | @Name( "referenceSessionFactory" )
  | @Scope( ScopeType.APPLICATION )
  | @Intercept( InterceptionType.NEVER )
  | public class ReferenceSessionFactory
  | {
  |     @Unwrap
  |     public SessionFactory getSessionFactory()
  |     {
  |         return HibernateSession.getSessionFactory();
  |     }
  | }
  | 

And a test component


  | @Name( "test1" )
  | @Scope( ScopeType.EVENT )
  | public class Test1
  | {
  |     @In( create = true )
  |     private Session referenceSession;
  | 
  |     @Create
  |     public void init()
  |     {
  |         int i = 1;
  |     }
  | 
  |     public String getStr()
  |     {
  |         return "test1";
  |     }
  | }
  | 

and the components.xml piece.


  |   <!-- reference session factory wrapper component -->
  |   <component class="com.azure.spark.web.seam.component.ReferenceSessionFactory" auto-create="true"/>
  | 
  |   <!-- managed session from the reference session factory -->
  |   <core:managed-hibernate-session name="referenceSession" session-factory="#{referenceSessionFactory}"/>
  | 
  |   <component class="com.azure.spark.web.bean.security.Test1"/>
  | 

And my simple test page


  | <?xml version="1.0" encoding="UTF-8"?>
  | <!DOCTYPE html
  |      PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  |      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  | <html xmlns="http://www.w3.org/1999/xhtml"
  |       xmlns:ui="http://java.sun.com/jsf/facelets"
  |       xmlns:f="http://java.sun.com/jsf/core"
  |       xmlns:h="http://java.sun.com/jsf/html">
  |   <head>
  |     <title></title>
  |   </head>
  |   <body>
  |     <h:outputText value="#{test1.str}"/>
  |   </body>
  | </html>
  | 

Now if I request a page that references the test1 component str property I get the following error.


  | java.lang.IllegalStateException: SessionFactory not found
  | 	at org.jboss.seam.core.ManagedHibernateSession.getSessionFactoryFromJndiOrValueBinding(ManagedHibernateSession.java:156)
  | 	at org.jboss.seam.core.ManagedHibernateSession.createSession(ManagedHibernateSession.java:81)
  | 	at org.jboss.seam.core.ManagedHibernateSession.create(ManagedHibernateSession.java:69)
  | 

If I remove the @Create annotation from the test1 component then it works as expected (page just renders "test1").

It seems that there is some problem creating and injecting the hibernate session when it is the @Create method that is being intercepted (I can see the Component.callCreateMethod() further down in the stack trace).  I haven't seen this problem injecting other components, facesContext and the referenceSessionFactory seem to work fine.

More interestingly if I visit the test page it fails as above.  If I visit a different page that has a hibernate session injected and no @Create it works fine.  Then if I go back and refresh the test page the error changes to...


  | java.lang.ClassCastException: com.azure.spark.web.seam.component.ReferenceSessionFactory
  | 	at org.jboss.seam.core.ManagedHibernateSession.getSessionFactoryFromJndiOrValueBinding(ManagedHibernateSession.java:153)
  | 	at org.jboss.seam.core.ManagedHibernateSession.createSession(ManagedHibernateSession.java:81)
  | 	at org.jboss.seam.core.ManagedHibernateSession.create(ManagedHibernateSession.java:69)
  | 

Which looks like it's finding something but it returns the Seam component itself rather than the result of the @Unwrap function.  This is also when intercepting the call to the @Create method of test1.

Appreciate any advice on whether I'm doing something wrong or if this is a possible bug.

Cheers.

Mike.

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

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4009400



More information about the jboss-user mailing list