2011年4月23日 星期六

[JPA] ObjectDB Manual (01 - Quick Tour)

* Defining a JPA Entity Class
  • A JPA annotated entity class as have the ability to represent objects in the database and similar to serializable classes.
  • By default, any field that is not declared as static or transient is a persistent field.


* Obtaining a JPA Database Connection
  • In JPA a database connection is represented by the EntityManager interface.
  • Operations that modify database content also require an EntityTransaction instance.
  • To obtain an instance of EntityManagerFactory that represents the relevant database.
  • Can use that factory instance to get an EntityManager instance.
    • Define a standard persistence unit in an XML file
    • Can simply provide the file path of the ObjectDB database.
  • Closing an EntityManager does not close the database itself.
  • Once the EntityManager object is closed it cannot be reused. But, the owning EntityManagerFactory instance may preserve the EntityManager's resources


* CRUD Database Operations with JPA
  • Operations that modify the content of the database (such as storing new objects) require an active transaction.
  • The EntityManager object serves as the factory for Query instances.
  • The getSingleResult method executes the query and returns the result. It should only be used when exactly one result value is expected (a single Long object in the query above).
  • The TypedQuery interface is a type safe subinterface of Query and is usually the preferred way to work with queries.
  • The EntityManager that manages an entity is responsible for automatically detecting changes to the entity object and applying them to the database when the transaction is committed.



* Reference
- ObjectDB 2.2 Developer's Guide

沒有留言:

張貼留言