Java Doc for JpaTemplate.java in  » J2EE » spring-framework-2.5 » org » springframework » orm » jpa » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » spring framework 2.5 » org.springframework.orm.jpa 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.springframework.orm.jpa.EntityManagerFactoryAccessor
      org.springframework.orm.jpa.JpaAccessor
         org.springframework.orm.jpa.JpaTemplate

JpaTemplate
public class JpaTemplate extends JpaAccessor implements JpaOperations(Code)
Helper class that allows for writing JPA data access code in the same style as with Spring's well-known JdoTemplate and HibernateTemplate classes. Automatically converts PersistenceExceptions into Spring DataAccessExceptions, following the org.springframework.dao exception hierarchy.

The central method is of this template is "execute", supporting JPA access code implementing the JpaCallback interface. It provides JPA EntityManager handling such that neither the JpaCallback implementation nor the calling code needs to explicitly care about retrieving/closing EntityManagers, or handling JPA lifecycle exceptions.

Can be used within a service implementation via direct instantiation with a EntityManagerFactory reference, or get prepared in an application context and given to services as bean reference. Note: The EntityManagerFactory should always be configured as bean in the application context, in the first case given to the service directly, in the second case to the prepared template.

NOTE: JpaTemplate mainly exists as a sibling of JdoTemplate and HibernateTemplate, offering the same style for people used to it. For newly started projects, consider adopting the standard JPA style of coding data access objects instead, based on a "shared EntityManager" reference injected via a Spring bean definition or the JPA PersistenceContext annotation. (Using Spring's SharedEntityManagerBean / PersistenceAnnotationBeanPostProcessor, or using a direct JNDI lookup for an EntityManager on a Java EE 5 server.)

JpaTemplate can be considered as direct alternative to working with the native JPA EntityManager API (through a shared EntityManager reference, as outlined above). The major advantage is its automatic conversion to DataAccessExceptions; the major disadvantage is that it introduces another thin layer on top of the native JPA API. Note that exception translation can also be achieved through AOP advice; check out org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor .

LocalContainerEntityManagerFactoryBean is the preferred way of obtaining a reference to an EntityManagerFactory, at least outside of a full Java EE 5 environment. The Spring application context will manage its lifecycle, initializing and shutting down the factory as part of the application. Within a Java EE 5 environment, you will typically work with a server-managed EntityManagerFactory that is exposed via JNDI, obtained through Spring's org.springframework.jndi.JndiObjectFactoryBean .
author:
   Juergen Hoeller
since:
   2.0
See Also:   JpaTemplate.setEntityManagerFactory
See Also:   JpaCallback
See Also:   javax.persistence.EntityManager
See Also:   LocalEntityManagerFactoryBean
See Also:   LocalContainerEntityManagerFactoryBean
See Also:   JpaTransactionManager
See Also:   org.springframework.transaction.jta.JtaTransactionManager
See Also:   org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
See Also:   org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor




Constructor Summary
public  JpaTemplate()
     Create a new JpaTemplate instance.
public  JpaTemplate(EntityManagerFactory emf)
     Create a new JpaTemplate instance.
public  JpaTemplate(EntityManager em)
     Create a new JpaTemplate instance.

Method Summary
public  booleancontains(Object entity)
    
protected  EntityManagercreateEntityManagerProxy(EntityManager em)
     Create a close-suppressing proxy for the given JPA EntityManager.
public  Objectexecute(JpaCallback action)
    
public  Objectexecute(JpaCallback action, boolean exposeNativeEntityManager)
     Execute the action specified by the given action object within a EntityManager.
public  ListexecuteFind(JpaCallback action)
    
public  Tfind(Class<T> entityClass, Object id)
    
public  Listfind(String queryString)
    
public  Listfind(String queryString, Object... values)
    
public  ListfindByNamedParams(String queryString, Map<String, ? extends Object> params)
    
public  ListfindByNamedQuery(String queryName)
    
public  ListfindByNamedQuery(String queryName, Object... values)
    
public  ListfindByNamedQueryAndNamedParams(String queryName, Map<String, ? extends Object> params)
    
public  voidflush()
    
public  TgetReference(Class<T> entityClass, Object id)
    
public  booleanisExposeNativeEntityManager()
     Return whether to expose the native JPA EntityManager to JpaCallback code, or rather an EntityManager proxy.
public  Tmerge(T entity)
    
public  voidpersist(Object entity)
    
public  voidrefresh(Object entity)
    
public  voidremove(Object entity)
    
public  voidsetExposeNativeEntityManager(boolean exposeNativeEntityManager)
     Set whether to expose the native JPA EntityManager to JpaCallback code.


Constructor Detail
JpaTemplate
public JpaTemplate()(Code)
Create a new JpaTemplate instance.



JpaTemplate
public JpaTemplate(EntityManagerFactory emf)(Code)
Create a new JpaTemplate instance.
Parameters:
  emf - EntityManagerFactory to create EntityManagers



JpaTemplate
public JpaTemplate(EntityManager em)(Code)
Create a new JpaTemplate instance.
Parameters:
  em - EntityManager to use




Method Detail
contains
public boolean contains(Object entity) throws DataAccessException(Code)



createEntityManagerProxy
protected EntityManager createEntityManagerProxy(EntityManager em)(Code)
Create a close-suppressing proxy for the given JPA EntityManager. The proxy also prepares returned JPA Query objects.
Parameters:
  em - the JPA EntityManager to create a proxy for the EntityManager proxy, implementing all interfacesimplemented by the passed-in EntityManager object (that is,also implementing all provider-specific extension interfaces)
See Also:   javax.persistence.EntityManager.close



execute
public Object execute(JpaCallback action) throws DataAccessException(Code)



execute
public Object execute(JpaCallback action, boolean exposeNativeEntityManager) throws DataAccessException(Code)
Execute the action specified by the given action object within a EntityManager.
Parameters:
  action - callback object that specifies the JPA action
Parameters:
  exposeNativeEntityManager - whether to expose the nativeJPA entity manager to callback code a result object returned by the action, or null
throws:
  org.springframework.dao.DataAccessException - in case of JPA errors



executeFind
public List executeFind(JpaCallback action) throws DataAccessException(Code)



find
public T find(Class<T> entityClass, Object id) throws DataAccessException(Code)



find
public List find(String queryString) throws DataAccessException(Code)



find
public List find(String queryString, Object... values) throws DataAccessException(Code)



findByNamedParams
public List findByNamedParams(String queryString, Map<String, ? extends Object> params) throws DataAccessException(Code)



findByNamedQuery
public List findByNamedQuery(String queryName) throws DataAccessException(Code)



findByNamedQuery
public List findByNamedQuery(String queryName, Object... values) throws DataAccessException(Code)



findByNamedQueryAndNamedParams
public List findByNamedQueryAndNamedParams(String queryName, Map<String, ? extends Object> params) throws DataAccessException(Code)



flush
public void flush() throws DataAccessException(Code)



getReference
public T getReference(Class<T> entityClass, Object id) throws DataAccessException(Code)



isExposeNativeEntityManager
public boolean isExposeNativeEntityManager()(Code)
Return whether to expose the native JPA EntityManager to JpaCallback code, or rather an EntityManager proxy.



merge
public T merge(T entity) throws DataAccessException(Code)



persist
public void persist(Object entity) throws DataAccessException(Code)



refresh
public void refresh(Object entity) throws DataAccessException(Code)



remove
public void remove(Object entity) throws DataAccessException(Code)



setExposeNativeEntityManager
public void setExposeNativeEntityManager(boolean exposeNativeEntityManager)(Code)
Set whether to expose the native JPA EntityManager to JpaCallback code. Default is "false": a EntityManager proxy will be returned, suppressing close calls and automatically applying transaction timeouts (if any).

As there is often a need to cast to a provider-specific EntityManager class in DAOs that use the JPA 1.0 API, for JPA 2.0 previews and other provider-specific functionality, the exposed proxy implements all interfaces implemented by the original EntityManager. If this is not sufficient, turn this flag to "true".
See Also:   JpaCallback
See Also:   javax.persistence.EntityManager




Methods inherited from org.springframework.orm.jpa.JpaAccessor
public void afterPropertiesSet()(Code)(Java Doc)
protected void flushIfNecessary(EntityManager em, boolean existingTransaction) throws PersistenceException(Code)(Java Doc)
public EntityManager getEntityManager()(Code)(Java Doc)
public JpaDialect getJpaDialect()(Code)(Java Doc)
public boolean isFlushEager()(Code)(Java Doc)
public void setEntityManager(EntityManager entityManager)(Code)(Java Doc)
public void setFlushEager(boolean flushEager)(Code)(Java Doc)
public void setJpaDialect(JpaDialect jpaDialect)(Code)(Java Doc)
public RuntimeException translateIfNecessary(RuntimeException ex)(Code)(Java Doc)

Fields inherited from org.springframework.orm.jpa.EntityManagerFactoryAccessor
final protected Log logger(Code)(Java Doc)

Methods inherited from org.springframework.orm.jpa.EntityManagerFactoryAccessor
protected EntityManager createEntityManager() throws IllegalStateException(Code)(Java Doc)
public EntityManagerFactory getEntityManagerFactory()(Code)(Java Doc)
public Map getJpaPropertyMap()(Code)(Java Doc)
protected EntityManager getTransactionalEntityManager() throws IllegalStateException(Code)(Java Doc)
public void setEntityManagerFactory(EntityManagerFactory emf)(Code)(Java Doc)
public void setJpaProperties(Properties jpaProperties)(Code)(Java Doc)
public void setJpaPropertyMap(Map jpaProperties)(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.