JPA Entity Manager resource handling

Posted by chiragshahkapadia on Stack Overflow See other posts from Stack Overflow or by chiragshahkapadia
Published on 2010-05-05T21:45:32Z Indexed on 2010/05/06 2:58 UTC
Read the original article Hit count: 322

Filed under:
|
|
|
|

Every time I call JPA method its creating entity and binding query.

My persistence properties are:

<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
<property name="hibernate.cache.provider_class"   value="net.sf.ehcache.hibernate.SingletonEhCacheProvider"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>

And I am creating entity manager the way shown below:

emf = Persistence.createEntityManagerFactory("pu");
em = emf.createEntityManager();
em = Persistence.createEntityManagerFactory("pu").createEntityManager();

Is there any nice way to manage entity manager resource instead create new every time or any property can set in persistence. Remember it's JPA.

See below binding log every time :

15:35:15,527 INFO  [AnnotationBinder] Binding entity from annotated class: *
15:35:15,527 INFO  [QueryBinder] Binding Named query: * => *
15:35:15,527 INFO  [QueryBinder] Binding Named query: * => *
15:35:15,527 INFO  [QueryBinder] Binding Named query: 
15:35:15,527 INFO  [QueryBinder] Binding Named query: 
15:35:15,527 INFO  [QueryBinder] Binding Named query: 
15:35:15,527 INFO  [QueryBinder] Binding Named query: 
15:35:15,527 INFO  [QueryBinder] Binding Named query: 
15:35:15,527 INFO  [QueryBinder] Binding Named query: 
15:35:15,527 INFO  [QueryBinder] Binding Named query: 
15:35:15,527 INFO  [EntityBinder] Bind entity com.* on table *
15:35:15,542 INFO  [HibernateSearchEventListenerRegister] Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
15:35:15,542 INFO  [NamingHelper] JNDI InitialContext properties:{}
15:35:15,542 INFO  [DatasourceConnectionProvider] Using datasource: 
15:35:15,542 INFO  [SettingsFactory] RDBMS: 
and Real Application Testing options
15:35:15,542 INFO  [SettingsFactory] JDBC driver: Oracle JDBC driver, version: 9.2.0.1.0
15:35:15,542 INFO  [Dialect] Using dialect: org.hibernate.dialect.Oracle10gDialect
15:35:15,542 INFO  [TransactionFactoryFactory] Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
15:35:15,542 INFO  [TransactionManagerLookupFactory] No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recomm
ended)
15:35:15,542 INFO  [SettingsFactory] Automatic flush during beforeCompletion(): disabled
15:35:15,542 INFO  [SettingsFactory] Automatic session close at end of transaction: disabled
15:35:15,542 INFO  [SettingsFactory] JDBC batch size: 15
15:35:15,542 INFO  [SettingsFactory] JDBC batch updates for versioned data: disabled
15:35:15,542 INFO  [SettingsFactory] Scrollable result sets: enabled
15:35:15,542 INFO  [SettingsFactory] JDBC3 getGeneratedKeys(): disabled
15:35:15,542 INFO  [SettingsFactory] Connection release mode: auto
15:35:15,542 INFO  [SettingsFactory] Default batch fetch size: 1
15:35:15,542 INFO  [SettingsFactory] Generate SQL with comments: disabled
15:35:15,542 INFO  [SettingsFactory] Order SQL updates by primary key: disabled
15:35:15,542 INFO  [SettingsFactory] Order SQL inserts for batching: disabled
15:35:15,542 INFO  [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
15:35:15,542 INFO  [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
15:35:15,542 INFO  [SettingsFactory] Query language substitutions: {}
15:35:15,542 INFO  [SettingsFactory] JPA-QL strict compliance: enabled
15:35:15,542 INFO  [SettingsFactory] Second-level cache: enabled
15:35:15,542 INFO  [SettingsFactory] Query cache: enabled
15:35:15,542 INFO  [SettingsFactory] Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
15:35:15,542 INFO  [RegionFactoryCacheProviderBridge] Cache provider: net.sf.ehcache.hibernate.SingletonEhCacheProvider
15:35:15,542 INFO  [SettingsFactory] Optimize cache for minimal puts: disabled
15:35:15,542 INFO  [SettingsFactory] Structured second-level cache entries: disabled
15:35:15,542 INFO  [SettingsFactory] Query cache factory: org.hibernate.cache.StandardQueryCacheFactory
15:35:15,542 INFO  [SettingsFactory] Statistics: disabled
15:35:15,542 INFO  [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
15:35:15,542 INFO  [SettingsFactory] Default entity-mode: pojo
15:35:15,542 INFO  [SettingsFactory] Named query checking : enabled
15:35:15,542 INFO  [SessionFactoryImpl] building session factory
15:35:15,542 INFO  [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
15:35:15,542 INFO  [UpdateTimestampsCache] starting update timestamps cache at region: org.hibernate.cache.UpdateTimestampsCache
15:35:15,542 INFO  [StandardQueryCache] starting query cache at region: org.hibernate.cache.StandardQueryCache

© Stack Overflow or respective owner

Related posts about jpa

Related posts about jboss