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.
| Online: | 17 Members of 4546 |
| Forum: Seam Users |
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.
try java:/myDatabase
Source code in
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.