|
Oracle TopLink Java API Reference 10g Release 3 (10.1.3.1) B28219-01 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Interface used to interact with the persistence context.
Method Summary | |
void |
close() Closes this EntityManager. |
boolean |
contains(java.lang.Object entity) Check if the instance belongs to the current persistence context. |
Query |
createNamedQuery(java.lang.String name) Create an instance of Query for executing a named query (in EJBQL or native SQL). |
Query |
createNativeQuery(java.lang.String sqlString) Create an instance of Query for executing a native SQL query. |
Query |
createNativeQuery(java.lang.String sqlString, java.lang.Class resultClass) Create an instance of Query for executing a native SQL query. |
Query |
createNativeQuery(java.lang.String sqlString, java.lang.String resultSetMapping) Create an instance of Query for executing a native SQL query. |
Query |
createQuery(java.lang.String ejbqlString) Create an instance of Query for executing an EJBQL query. |
java.lang.Object |
find(java.lang.Class entityClass, java.lang.Object primaryKey) Find by primary key. |
java.lang.Object |
find(java.lang.String entityName, java.lang.Object primaryKey) Find by primary key. |
void |
flush() Synchronize the persistence context with the underlying database. |
EntityTransaction |
getUserTransaction() Looks up the current user transaction. |
boolean |
isOpen() Indicates whether or not this entity manager is open. |
java.lang.Object |
merge(java.lang.Object entity) Merge the state of the given entity into the current persistence context, using the unqualified class name as the entity name. |
void |
persist(java.lang.Object entity) Make an instance managed, using the unqualified class name as the entity name. |
void |
refresh(java.lang.Object entity) Refresh the state of the instance from the database. |
void |
remove(java.lang.Object entity) Remove the instance. |
Method Detail |
public void persist(java.lang.Object entity)
entity
-public java.lang.Object merge(java.lang.Object entity)
entity
-public void remove(java.lang.Object entity)
entity
-public void refresh(java.lang.Object entity)
entity
-java.lang.IllegalArgumentException
- if not an entity or entity is not in managed stateTransactionRequiredException
- if there is no transactionpublic java.lang.Object find(java.lang.String entityName, java.lang.Object primaryKey)
entityName
-primaryKey
-public java.lang.Object find(java.lang.Class entityClass, java.lang.Object primaryKey)
entityClass
-primaryKey
-public void flush()
public Query createQuery(java.lang.String ejbqlString)
ejbqlString
- an EJBQL query stringpublic Query createNamedQuery(java.lang.String name)
name
- the name of a query defined in metadatapublic Query createNativeQuery(java.lang.String sqlString)
sqlString
- a native SQL query stringpublic Query createNativeQuery(java.lang.String sqlString, java.lang.Class resultClass)
sqlString
- a native SQL query stringresultClass
- the class of the resulting instancesjava.lang.IllegalArgumentException
- if query string is not validpublic Query createNativeQuery(java.lang.String sqlString, java.lang.String resultSetMapping)
sqlString
- a native SQL query stringresultSetMapping
- the name of the result set mappingjava.lang.IllegalArgumentException
- if query string is not validpublic boolean contains(java.lang.Object entity)
entity
-public void close()
Closes this EntityManager. This can only be called when the transaction that this EntityManager is associated with has a status of Status#STATUS_NO_TRANSACTION
, Status#Status_COMMITTED
or Status#STATUS_ROLLEDBACK
. It will throw an IllegalStateException
if invoked when this condition is not true.
After invoking this method, all methods on the instance will throw an IllegalStateException
except for isOpen()
, which will return false
.
This should be called when a method is finished with the EntityManager in a bean-managed transaction environment or when executed outside a container. Closing of the EntityManager is handled by the container when using container-managed transactions.
public boolean isOpen()
true
until a call to close()
is made.public EntityTransaction getUserTransaction()
Looks up the current user transaction. This may cause an exception to be raised if a UserTransaction is not accessible. If outside a managed environment, JTA semantics are emulated.
This always returns a UserTransaction when outside a container and equates to a simple JNDI lookup on the UserTransaction when inside the Container. The returned UserTransaction may or may not be a proxy around the actual object.
Inside a container, the EM will use the TransactionManager as a means to synchronize, but outside the Container the EM is tightly coupled with (essentially it implements) the TransactionManager.
|
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |