Java Doc for EntityManager.java in  » Database-ORM » toplink » javax » persistence » 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 » Database ORM » toplink » javax.persistence 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


javax.persistence.EntityManager

EntityManager
public interface EntityManager (Code)
Interface used to interact with the persistence context.

An EntityManager instance is associated with a persistence context. A persistence context is a set of entity instances in which for any persistent entity identity there is a unique entity instance. Within the persistence context, the entity instances and their lifecycle are managed. This interface defines the methods that are used to interact with the persistence context. The EntityManager API is used to create and remove persistent entity instances, to find entities by their primary key, and to query over entities.

The set of entities that can be managed by a given EntityManager instance is defined by a persistence unit. A persistence unit defines the set of all classes that are related or grouped by the application, and which must be colocated in their mapping to a single database.
since:
   Java Persistence 1.0





Method Summary
public  voidclear()
     Clear the persistence context, causing all managed entities to become detached.
public  voidclose()
     Close an application-managed EntityManager.
public  booleancontains(Object entity)
     Check if the instance belongs to the current persistence context.
public  QuerycreateNamedQuery(String name)
     Create an instance of Query for executing a named query (in the Java Persistence query language or in native SQL).
public  QuerycreateNativeQuery(String sqlString)
     Create an instance of Query for executing a native SQL statement, e.g., for update or delete.
public  QuerycreateNativeQuery(String sqlString, Class resultClass)
     Create an instance of Query for executing a native SQL query.
public  QuerycreateNativeQuery(String sqlString, String resultSetMapping)
     Create an instance of Query for executing a native SQL query.
public  QuerycreateQuery(String qlString)
     Create an instance of Query for executing a Java Persistence query language statement.
public  Tfind(Class<T> entityClass, Object primaryKey)
     Find by primary key.
public  voidflush()
     Synchronize the persistence context to the underlying database.
public  ObjectgetDelegate()
     Return the underlying provider object for the EntityManager, if available.
public  FlushModeTypegetFlushMode()
     Get the flush mode that applies to all objects contained in the persistence context.
public  TgetReference(Class<T> entityClass, Object primaryKey)
     Get an instance, whose state may be lazily fetched. If the requested instance does not exist in the database, throws EntityNotFoundException when the instance state is first accessed.
public  EntityTransactiongetTransaction()
     Returns the resource-level transaction object.
public  booleanisOpen()
     Determine whether the EntityManager is open.
public  voidjoinTransaction()
     Indicate to the EntityManager that a JTA transaction is active.
public  voidlock(Object entity, LockModeType lockMode)
     Set the lock mode for an entity object contained in the persistence context.
public  Tmerge(T entity)
     Merge the state of the given entity into the current persistence context.
public  voidpersist(Object entity)
     Make an entity instance managed and persistent.
public  voidrefresh(Object entity)
     Refresh the state of the instance from the database, overwriting changes made to the entity, if any.
public  voidremove(Object entity)
     Remove the entity instance.
public  voidsetFlushMode(FlushModeType flushMode)
     Set the flush mode that applies to all objects contained in the persistence context.



Method Detail
clear
public void clear()(Code)
Clear the persistence context, causing all managed entities to become detached. Changes made to entities that have not been flushed to the database will not be persisted.
throws:
  IllegalStateException - if this EntityManager has been closed.



close
public void close()(Code)
Close an application-managed EntityManager. After the close method has been invoked, all methods on the EntityManager instance and any Query objects obtained from it will throw the IllegalStateException except for getTransaction and isOpen (which will return false). If this method is called when the EntityManager is associated with an active transaction, the persistence context remains managed until the transaction completes.
throws:
  IllegalStateException - if the EntityManageris container-managed or has been already closed..



contains
public boolean contains(Object entity)(Code)
Check if the instance belongs to the current persistence context.
Parameters:
  entity - true if the instance belongs to the current persistence context.
throws:
  IllegalStateException - if this EntityManager has been closed.
throws:
  IllegalArgumentException - if not an entity



createNamedQuery
public Query createNamedQuery(String name)(Code)
Create an instance of Query for executing a named query (in the Java Persistence query language or in native SQL).
Parameters:
  name - the name of a query defined in metadata the new query instance
throws:
  IllegalStateException - if this EntityManager has been closed.
throws:
  IllegalArgumentException - if a query has not beendefined with the given name



createNativeQuery
public Query createNativeQuery(String sqlString)(Code)
Create an instance of Query for executing a native SQL statement, e.g., for update or delete.
Parameters:
  sqlString - a native SQL query string the new query instance
throws:
  IllegalStateException - if this EntityManager has been closed.



createNativeQuery
public Query createNativeQuery(String sqlString, Class resultClass)(Code)
Create an instance of Query for executing a native SQL query.
Parameters:
  sqlString - a native SQL query string
Parameters:
  resultClass - the class of the resulting instance(s) the new query instance
throws:
  IllegalStateException - if this EntityManager has been closed.



createNativeQuery
public Query createNativeQuery(String sqlString, String resultSetMapping)(Code)
Create an instance of Query for executing a native SQL query.
Parameters:
  sqlString - a native SQL query string
Parameters:
  resultSetMapping - the name of the result set mapping the new query instance
throws:
  IllegalStateException - if this EntityManager has been closed.



createQuery
public Query createQuery(String qlString)(Code)
Create an instance of Query for executing a Java Persistence query language statement.
Parameters:
  qlString - a Java Persistence query language query string the new query instance
throws:
  IllegalStateException - if this EntityManager has been closed.
throws:
  IllegalArgumentException - if query string is not valid



find
public T find(Class<T> entityClass, Object primaryKey)(Code)
Find by primary key.
Parameters:
  entityClass -
Parameters:
  primaryKey - the found entity instance or nullif the entity does not exist
throws:
  IllegalStateException - if this EntityManager has been closed.
throws:
  IllegalArgumentException - if the first argument doesnot denote an entity type or the secondargument is not a valid type for thatentity's primary key



flush
public void flush()(Code)
Synchronize the persistence context to the underlying database.
throws:
  IllegalStateException - if this EntityManager has been closed.
throws:
  TransactionRequiredException - if there isno transaction
throws:
  PersistenceException - if the flush fails



getDelegate
public Object getDelegate()(Code)
Return the underlying provider object for the EntityManager, if available. The result of this method is implementation specific.
throws:
  IllegalStateException - if this EntityManager has been closed.



getFlushMode
public FlushModeType getFlushMode()(Code)
Get the flush mode that applies to all objects contained in the persistence context. flush mode
throws:
  IllegalStateException - if this EntityManager has been closed.



getReference
public T getReference(Class<T> entityClass, Object primaryKey)(Code)
Get an instance, whose state may be lazily fetched. If the requested instance does not exist in the database, throws EntityNotFoundException when the instance state is first accessed. (The persistence provider runtime is permitted to throw EntityNotFoundException when EntityManager.getReference is called.) The application should not expect that the instance state will be available upon detachment, unless it was accessed by the application while the entity manager was open.
Parameters:
  entityClass -
Parameters:
  primaryKey - the found entity instance
throws:
  IllegalStateException - if this EntityManager has been closed.
throws:
  IllegalArgumentException - if the first argument doesnot denote an entity type or the secondargument is not a valid type for thatentity's primary key
throws:
  EntityNotFoundException - if the entity statecannot be accessed



getTransaction
public EntityTransaction getTransaction()(Code)
Returns the resource-level transaction object. The EntityTransaction instance may be used serially to begin and commit multiple transactions. EntityTransaction instance
throws:
  IllegalStateException - if invoked on a JTAEntityManager.



isOpen
public boolean isOpen()(Code)
Determine whether the EntityManager is open. true until the EntityManager has been closed.



joinTransaction
public void joinTransaction()(Code)
Indicate to the EntityManager that a JTA transaction is active. This method should be called on a JTA application managed EntityManager that was created outside the scope of the active transaction to associate it with the current JTA transaction.
throws:
  IllegalStateException - if this EntityManager has been closed.
throws:
  TransactionRequiredException - if there isno transaction.



lock
public void lock(Object entity, LockModeType lockMode)(Code)
Set the lock mode for an entity object contained in the persistence context.
Parameters:
  entity -
Parameters:
  lockMode -
throws:
  IllegalStateException - if this EntityManager has been closed.
throws:
  PersistenceException - if an unsupported lock callis made
throws:
  IllegalArgumentException - if the instance is notan entity or is a detached entity
throws:
  TransactionRequiredException - if there is notransaction



merge
public T merge(T entity)(Code)
Merge the state of the given entity into the current persistence context.
Parameters:
  entity - the instance that the state was merged to
throws:
  IllegalStateException - if this EntityManager has been closed.
throws:
  IllegalArgumentException - if instance is not anentity or is a removed entity
throws:
  TransactionRequiredException - if invoked on acontainer-managed entity manager of typePersistenceContextType.TRANSACTION and there isno transaction.



persist
public void persist(Object entity)(Code)
Make an entity instance managed and persistent.
Parameters:
  entity -
throws:
  EntityExistsException - if the entity already exists.(The EntityExistsException may be thrown when the persistoperation is invoked, or the EntityExistsException oranother PersistenceException may be thrown at flush or committime.)
throws:
  IllegalStateException - if this EntityManager has been closed.
throws:
  IllegalArgumentException - if not an entity
throws:
  TransactionRequiredException - if invoked on acontainer-managed entity manager of typePersistenceContextType.TRANSACTION and there isno transaction.



refresh
public void refresh(Object entity)(Code)
Refresh the state of the instance from the database, overwriting changes made to the entity, if any.
Parameters:
  entity -
throws:
  IllegalStateException - if this EntityManager has been closed.
throws:
  IllegalArgumentException - if not an entityor entity is not managed
throws:
  TransactionRequiredException - if invoked on acontainer-managed entity manager of typePersistenceContextType.TRANSACTION and there isno transaction.
throws:
  EntityNotFoundException - if the entity no longerexists in the database.



remove
public void remove(Object entity)(Code)
Remove the entity instance.
Parameters:
  entity -
throws:
  IllegalStateException - if this EntityManager has been closed.
throws:
  IllegalArgumentException - if not an entityor if a detached entity
throws:
  TransactionRequiredException - if invoked on acontainer-managed entity manager of typePersistenceContextType.TRANSACTION and there isno transaction.



setFlushMode
public void setFlushMode(FlushModeType flushMode)(Code)
Set the flush mode that applies to all objects contained in the persistence context.
Parameters:
  flushMode -
throws:
  IllegalStateException - if this EntityManager has been closed.



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