Help

Controls

PermLinkWikiLink

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

Forum: Seam Users Forum ListTopic List
12. Aug 2008, 22:29 CET | Link

I have the following in my components.xml:

<persistence:managed-hibernate-session name="myDatabase" auto-create="true"
session-factory-jndi-name="myDatabase"/>

In CONVERSATION scoped components I can inject Session myDatabase; I would like to, from an APPLICATION scoped component, get a Session. I do it like this:

String jndiName = "/myDatabase";
SessionFactory factory = (SessionFactory) org.jboss.seam.util.Naming
    .getInitialContext()
    .lookup( jndiName );
Session myDatabase = factory.openSession();

Make sure to close the Session when you are done with it.

1 Reply:
13. Aug 2008, 15:33 CET | Link

try java:/myDatabase

Source code in

org.jboss.seam.persistence.ManagedPersistenceContext
seems to hint at that.

@Create
   public void create(Component component)
   {
      this.componentName = component.getName();
      if (persistenceUnitJndiName==null)
      {
         persistenceUnitJndiName = "java:/" + componentName;
      }
      
      PersistenceContexts.instance().touch(componentName);      
   }

If for some reasons this fails you can use hibernate feature to publish sessionfactory in global jndi namespace by adding the following to your persistence.xml.

<property name="hibernate.session_factory_name" value="java:/mySessionFactory" />