This link has been bookmarked by 2 people . It was first bookmarked on 09 Nov 2007, by Vero Velez.
-
10 May 08
-
. In order to perform database queries, the BookDBAO object needs to obtain an EntityManager instance.
-
Because the web container does not manage JavaBeans components, you cannot inject resources into them
-
the ContextListener object creates the BookDBAO object and puts it into application scope
-
you can bypass injecting EntityManagerFactory and instead inject the EntityManager directly into BookDBAO
-
a persistence context, which is a set of entity instances that the entity manager is tasked with managing
-
Accessing Data from the Database
After the BookDBAO object obtains an EntityManager instance, it can access data from the database. The getBooks method of BookDBAO calls the createQuery method of the EntityManager instance to retrieve a list of all books by bookId:
public List getBooks() throws BooksNotFoundException { try { return em.createQuery( "SELECT bd FROM Book bd ORDER BY bd.bookId"). getResultList(); } catch(Exception ex){ throw new BooksNotFoundException("Could not get books: " + ex.getMessage()); } } -
UserTransaction is an interface to the underlying JTA transaction manager used to begin a new transaction and end a transaction
-
-
09 Nov 07
-
managing the object/relational mapping
-
A Java object that maps to a database table is called an entity class
-
with properties that map to columns in the database table.
-
POJO,
-
EntityManager interface
-
interface provides methods that perform common database functions, such as querying and updating the database
-
BookDBAO class of the Duke’s Bookstore application uses the entity manager to query the database for the book data and to update the inventory of books that are sold.
-
oes not need to explicitly create a connection to the data source
-
properties include information such as the location of the database server, the name of the database, the network protocol to use to communicate with the server, and so on
-
onfigured by a descriptor file called persistence.xml.
-
n entity manager
-
set of entities
-
entity manager are defined in a persistence unit.
-
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.