Frameworks| Hibernate| Struts| JSF| JavaFX| Ajax| Spring| DOJO| JDO| iBatis| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Persistence 
 

The Java Enterprise Edition (J2EE) supports JPA and supply a persistence provider. It uses the following elements to allow persistence management in EJB 3.0.

 

Persistence

                         

There are following JPA persistence provider:

The Java Enterprise Edition (J2EE) supports JPA and supply a persistence provider. It uses the following elements to allow persistence management in EJB 3.0.

  1. Persistence: This is the persistence unit that consists declarative meta-data. It describes the relationship of entity class objects to the relational database. For creating the persistence context the EntityManagerFactory uses the meta-data. Which is accessed through the EntityManager.
      
  2. EntityManagerFactory: It is used for creating an EntityManger to interact with database. An application server is a container and supply this function, but the EntityManagerFactory is required if you are using JPA application-managed persistence. There are following example for creating a EntityManagerFactory:

    Example: 
    import javax.persistence.Persistence;
    import javax.persistence.EntityManagerFactory;

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("persistence_unit_name");

    // paste your code here according to your requirement

    emf.close();

     

  3. EntityManager: This is a resource manger that maintain an active entity objects, which is used by any applications. It manages the OR mapping meta-data and database inaction. The persistence context is represented by an instance of EntityManger. The EntityManager contains two classes: 1) javax.persistence.EntityManagerFactory and 2) javax.persistence.Persistence.  The Persistence class is a public class that retrieve the EntityManagerFactory for a given named persistence unit. There are following example that shows how to create a EntityManger:

    Example: 
    import javax.persistence.EntityManager;

    EntityManager em = emf.createEntityManager();

    // paste your code here according to your requirement

    em.close();

[Note: The injection of the EntityManager supports the following artifacts]

  • Create EJB 3.0 session beans
  • Crete EJB 3.0 message-driven beans
  • Creates a servlets, but injection doesn't support in JSP
  • Creates a main class of the application client

Query: The Java Persistence APIs defines the JPQL (JPA Query Language) that is used to select objects from data source. The JPQL query has an internal namespace which is declared in the from clause of the JPQL query.  In JPQL, we define an arbitrary identifiers for assigning the entities. See the following JPQL query.

Query q = em.createQuery ("SELECT s FROM Student s");

In above query 's' is identifier that is assigned to the entity Student.

[Note: We can use "as" keyword. This is optionally that can be used when declaring an identifier in the "from" clause. Ex: SELECT s FROM s and SELECT s FROM Student AS s is synonymous.]

                           

» View all related tutorials
Related Tags: c mvc com framework diff struts io components vi component this frame if work learn ram ear e il section

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.