Wednesday, July 21, 2010

JPA entities of state and API



Entity object has the following four states, these states occur by calling the EntityManager interface method of migration:

New state: the newly created entity object, yet have persistent primary key, and a persistence context does not associate. Controlled state: already have a persistent primary key and and the persistence context to establish a link; free State: have a persistent primary key, but not yet, and persistence context to establish contacts; delete state: has a persistent primary key has been, and persistence context to establish contacts However, arrangements have been deleted from the database.

The API EntityManager

Here are some of the main interface EntityManager methods:

void persist (Object entity)

By calling the EntityManager's persist () method, the new entity instance will be converted to control. This means that when the persist () method where the transaction commits, the entity data will be saved to the database. If the entity has been persistent, then the call to persist () operation does not occur anything. If an entity has been removed calls persist () operation to remove into another state entity controlled state. If the implementation of free-like entities persist () operation will throw IllegalArgumentException.

In an entity called persist () operation will be broadcast to the associated entities and entities on the implementation of the corresponding cascade persistence operations;

void remove (Object entity)

By calling remove () method to remove a controlled entity. If the entity declared as a cascading delete (cascade = REMOVE or cascade = ALL), was associated entities will be deleted. In a new state of the entity called remove () operation will be ignored. If the free entity called remove () operation throws IllegalArgumentException, related to the transaction will be rolled back. If the entity has been removed to perform remove () operation will be ignored;

void flush ()

The controlled state of the entity data synchronization to the database;

T merge (T entity)

A free state of the entity persistence to the database, and converted into a controlled state of the entity;

T find (Class entityClass, Object primaryKey)

To the primary key query entity objects, entityClass is the entity class, primaryKey is the primary key value, such as the following code to query entities Topic:

Topic t = em.find (Topic.class, 1);

Query createQuery (String qlString)

According to JPA's query to create a query object Query, such as the following code:



Query q = em.createQuery ("" SELECT t FROM Topic tWHERE t.topicTitle LIKE: topicTitle ")"); Query createNativeQuery (String sqlString) using a local database SQL statements to create a Query object, Query by getResultList () Method of implementation of the query, returns a List result set, each row of data corresponds to a Vector.
Query

JPA represents a query interface, using javax.persistence.Query instance, Query instance from the EntityManager query by specifying the building. This interface has many methods to perform data query interface:

Object getSingleResult (): implementation of the SELECT query and returns a result;

List getResultList (): implementation of the SELECT query and return multiple results;

Query setParameter (int position, Object value): binding by position number parameter in the parameter query, if the query using the command parameter, you can use Query setParameter (String name, Object value) method of binding named parameters;

Query setMaxResults (int maxResult): Set the maximum number of results returned;

int executeUpdate (): If the query is to add, delete, or change the statement, by the method of implementation of the update operation.







Recommended links:



Christmas-Idea VCD DAT TO Xbox 360



Vacations MP4 Converter



REVIEW Web Servers



Convert flv to 3gp



REVIEWS Graphic



Guide Audio Rippers And Converters



Silver DVD Editor



AaleSoft DVD to PSP CONVERTER



Burn4Free



Bluesea DVD To Apple TV DAT



what is mkv file



converting MP4 to mp3



Ps3 movie formats



Youtube To MOV Help



No comments:

Post a Comment