public static void main( String[] args ) { final PersistenceModule persistenceModule = new PersistenceModule() { @Override protected void configurePersistence() { bindApplicationManagedPersistenceUnit( "puName" ); } }; final Injector injector = Guice.createInjector( persistenceModule, getApplicationSpecificModules() ); final PersistenceService persistenceService = injector.getInstance( PersistenceService.class ); try { persistenceService.start(); while( notTerminated() ) { // run application } } finally { persistenceService.stop(); } }
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0"> <persistence-unit name="puName" transaction-type="RESOURCE_LOCAL"> <!-- your configuration --> </peristence-unit> </peristence>