Returns the current EntityManager instance.
Returns the current EntityManager instance. This leaves the implementor free to choose how they want to manage instances. For example, the implementor could use a ThreadLocal to allow for a singleton instance of ScalaEntityManager, or they could simply set up a val to hold the current instance.
This val should hold a reference to the factory that created this instance, so that the proper closeEM method can be called on shutdown.
Clears the persistence context.
Clears the persistence context. Changes made to any entities that have not been flushed to the database will not be persisted.
Closes the EntityManager.
Closes the EntityManager. Subclasses may override this if they desire different behavior.
Tests to see if the given entity is attached to the current EntityManager
Tests to see if the given entity is attached to the current EntityManager
The entity to check
true
if attached, false
otherwise
Creates a new ScalaQuery[A] using the given named query.
Creates a new ScalaQuery[A] using the given named query. The results of the named query should be of type A.
The named query to use
A new ScalaQuery[A] that uses the given named query
Creates a ScalaQuery representing the given named query with the given parameters set.
Creates a ScalaQuery representing the given named query with the given parameters set. This can be used if you want to use some of the extended functionality of ScalaQuery, such as pagination or using query hints. An example would be:
val query = EM.createNamedQuery[Book]("findAllBooks")
query.setFirstResult(20).setMaxResults(100)
The name of the query to execute
Zero or more pairs of (paramName,paramValue)
The created ScalaQuery[A]
Creates a new ScalaQuery[A] using the given native SQL query.
Creates a new ScalaQuery[A] using the given native SQL query. For more details on using native queries, see http://www.hibernate.org/hib_docs/entitymanager/reference/en/html/query_native.html.
The query string to use
The name of the mapping from the result set to entities
A new ScalaQuery[A] that uses the given native SQL
Creates a new ScalaQuery[A] using the given native SQL query.
Creates a new ScalaQuery[A] using the given native SQL query. For more details on using native queries, see http://www.hibernate.org/hib_docs/entitymanager/reference/en/html/query_native.html.
The query string to use
The class of the returned entities
A new ScalaQuery[A] that uses the given native SQL
Creates a new ScalaQuery[A] using the given native SQL query.
Creates a new ScalaQuery[A] using the given native SQL query. For more details on using native queries, see http://www.hibernate.org/hib_docs/entitymanager/reference/en/html/query_native.html.
The query string to use
A new ScalaQuery[A] that uses the given native SQL
Creates a new ScalaQuery[A] using the given query string.
Creates a new ScalaQuery[A] using the given query string. The results of the query should be of type A. See http://www.hibernate.org/hib_docs/entitymanager/reference/en/html/queryhql.html for an EJB-QL reference.
The query string (EJBQL)
A new ScalaQuery[A] that uses the given query string
Attempts to load a given entity based on its ID.
Attempts to load a given entity based on its ID. Returns an Option, with None indicating that no entity exists with the given ID.
The class of the entity to load
The ID of the entity to load
An Option with the loaded entity (Some) or None to indicate that an entity could not be loaded
Returns a List[A]
of the results of excuting the given query.
Returns a List[A]
of the results of excuting the given query.
Named parameters
may be provided to refine the query. Using Scala's syntax sugar for
Pairs and varargs, an example query might look like:
EM.findAll[User]("byUsername", "username" -> "fred")
The name of the query to execute
Zero or more pairs of (paramName,paramValue)
A List[A] representing the results of the query
Forces a flush of the current entity state to the database.
Returns the underlying provider object for the EntityManager.
Returns the underlying provider object for the EntityManager. Implementation-specific.
The underlying provider
Returns the current flush mode for the EntityManager
Returns the current flush mode for the EntityManager
javax.persistence.FlushModeType
Get an instance, whose state may be lazily fetched.
Get an instance, whose state may be lazily fetched. An EntityNotFoundException will be thrown when the instance is accessed if no corresponding instance exists in the database. The exception may be thrown when getReference is called.
The class of the instance
The primary key of the instance
A lazily fetched instance
Returns the current EM's transaction.
Returns the current EM's transaction. Note that this will throw an exception if you're using JTA for transactions.
The current transaction
Returns a boolean indicating whether the EntityManager is open.
Returns a boolean indicating whether the EntityManager is open.
true
if the EntityManager is open, false
otherwise
Joins the EM to the currently open JTA transaction.
Joins the EM to the currently open JTA transaction. Note that this throws and exception if no JTA transaction exists.
Locks the given entity using the given lock mode.
Locks the given entity using the given lock mode.
The entity to lock
The mode of the lock
javax.persistence.LockModeType
Merges the given entity and returns the newly merged copy.
Merges the given entity and returns the newly merged copy.
The entity to merge
The newly merged copy
Handles a merge and flush in a single method.
Handles a merge and flush in a single method. This is useful if your merge should check for constraint violations, since otherwise the merge won't occur until the transaction closes.
The entity to merge.
A newly merged copy of the entity. The original entity should be discarded.
Persists the given entity.
Persists the given entity.
The entity to persist
Handles a persist and flush in a single method.
Handles a persist and flush in a single method. This is useful if your persist should check for constraint violations, since otherwise the persist won't occur until the transaction closes.
The entity to persist.
Reloads a given entity's state from the database, effectively discarding any local changes.
Reloads a given entity's state from the database, effectively discarding any local changes.
The entity to refresh
Removes the given entity.
Removes the given entity.
The entity to remove
Handles a remove and flush in a single method.
Handles a remove and flush in a single method. This is useful if your remove should check for constraint violations, since otherwise the remove won't occur until the transaction closes.
The entity to remove.
Sets the flush mode for the EntityManager.
Sets the flush mode for the EntityManager.
The desired flush mode
javax.persistence.FlushModeType
This trait represents a Scalafied version of the standard EntityManager in JPA. In particular, queries are more type-safe and the find method returns an Option instead of possibly throwing an exception if the entity isn't found.
If you wish to provide a concrete implementation of this trait, you only need to provide the
em
method andfactory
val.