Category: Hibernate



Each archetype page should enforce the following pattern :

* Archetype name
* Command line to call the archetype
* If the archetype can be used in an existing projects directory
* A tree view of the resulting files
* Some additional information like the additional properties used by the plugin

To use an archetype:

mvn archetype:generate

Generate gives you a wizard that will walk you through the various choices.

or

mvn org.apache.maven.plugins:maven-archetype-plugin:1.0-alpha-7:create -DgroupId= -DartifactId= -DarchetypeArtifactId= -DarchetypeGroupId=

http://docs.codehaus.org/display/MAVENUSER/Archetypes+List

Additional Information

Maven Archtypes List – Generate Project archtypes using maven


The Java persistence API (JPA) allows you to store data from POJO’s (Plain old Java Objects) into database tables.

The persistence metadata is specified using Java annotations, XML mapping files or a combination of both. In case both are used then the XML information overwrites the annotations in the Java code. This persistence metadata defines the mapping to the database and the relationship between the objects.

JPA allows us to work with entity classes, which are denoted as such using the annotation @Entity or configured in an XML file (we’ll call this persistence meta information). When we acquire the Entity Manager Factory using the Persistence class, the Entity Manager Factory finds and processes the persistence meta information.

To work with a database using JPA, we need an Entity Manager. Before we can do that, we need to create an Entity Manager Factory.

  • EntityManagerFactory.jpeg

  • PersistenceSequence.jpg

To acquire an Entity Manager Factory, we use the class javax.persistence.Persistence. It reads a file called persistence.xml in the META-INF directory. It then creates the named Entity Manager Factory, which processes persistence meta information stored in XML files or annotations (we only use annotations).

Creating an Entity Manager once we have the Entity Manager Factory is simple:

  • CreateEntityManager.jpeg

Once we have an Entity Manager, we can ask it to perform several operations such as persisting or removing an entity from the database or creating a query.

Term Description
javax.persistence.Persistence This is a class used as an entry point for using JPA. The primary method you’ll use on this class is createEntityManagerFactory(“someName”) to retrieve an entity manager factory with the name “someName”. This class requires a file called persistence.xml to be in the class path under a directory called META-INF.
EntityManagerFactory An instance of this class provides a way to create entity managers. Entity Managers are not multi-thread safe so we need a way to create one per thread. This class provides that functionality. The Entity Manager Factory is the in-memory representation of a Persistence Unit.
EntityManager An Entity Manager is the interface in your underlying storage mechanism. It provides methods for persisting, merging, removing, retrieving and querying objects. It is not multi-thread safe so we need one per thread. The Entity Manager also serves as a first level cache. It maintains changes and then attempts to optimize changes to the database by batching them up when the transaction completes.
persistence.xml A required file that describes one or more persistence units. When you use the javax.persistence.Persistence class to look up an named Entity Manager Factory, the Persistence class looks for this file under the META-INF directory.
Persistence Unit A Persistence Unit has a name and it describes database connection information either directly (if working in a JSE environment) or indirectly by referencing a JNDI-defined data source (if working in a managed/JEE environment). A Persistence Unit can also specify the classes(entities) it should or should not manage .
Persistence Meta Information Information describing the configuration of entities and the database and the association between entity classes and the persistence units to which they relate. This is either through annotations added to classes or though XML files. Note that XML files take precedence over annotations.

JPA requires that you identify the classes that you will store in a database. JPA uses the term Entity to define classes that it will map to a relational database.

JPA is a specification and for using JPA you always need a JPA provider.

The JPA provider will use the persistence metadata information to perform the correct database operations.

Most JPA persistence provider offer the option to automatically create the database schema based on the metadata.

I will be soon compiling more information on JPA here.

Meanwhile you can access these links to get started.

http://blog.springsource.com/2006/05/30/getting-started-with-jpa-in-spring-20/

http://java.sun.com/javaee/overview/faq/persistence.jsp

http://schuchert.wikispaces.com/JPA+Tutorial+1+-+Getting+Started

http://www.vogella.de/articles/JavaPersistenceAPI/article.html#jpaintro

http://www.javabeat.net/articles/5-introduction-to-java-persistence-apijpa-1.html

only working example codes http://www.java2s.com/Code/Java/JPA/CatalogJPA.htm


1. What is Hibernate?

Hibernate is a powerful, high performance object/relational persistence and query service. This lets the users to develop persistent classes following object-oriented principles such as association, inheritance, polymorphism, composition, and collections.

2. What is ORM?

ORM stands for Object/Relational mapping. It is the programmed and translucent perseverance of objects in a Java application in to the tables of a relational database using the metadata that describes the mapping between the objects and the database. It works by transforming the data from one representation to another.

3. What does an ORM solution comprises of?

· It should have an API for performing basic CRUD (Create, Read, Update, Delete) operations on objects of persistent classes

· Should have a language or an API for specifying queries that refer to the classes and the properties of classes

· An ability for specifying mapping metadata

· It should have a technique for ORM implementation to interact with transactional objects to perform dirty checking, lazy association fetching, and other optimization functions

4. What are the different levels of ORM quality?

There are four levels defined for ORM quality.

i. Pure relational

ii. Light object mapping

iii. Medium object mapping

iv. Full object mapping

5. What is a pure relational ORM?

The entire application, including the user interface, is designed around the relational model and SQL-based relational operations.

6. What is a meant by light object mapping?

The entities are represented as classes that are mapped manually to the relational tables. The code is hidden from the business logic using specific design patterns. This approach is successful for applications with a less number of entities, or applications with common, metadata-driven data models. This approach is most known to all.

7. What is a meant by medium object mapping?

The application is designed around an object model. The SQL code is generated at build time. And the associations between objects are supported by the persistence mechanism, and queries are specified using an object-oriented expression language. This is best suited for medium-sized applications with some complex transactions. Used when the mapping exceeds 25 different database products at a time.

8. What is meant by full object mapping?

Full object mapping supports sophisticated object modeling: composition, inheritance, polymorphism and persistence. The persistence layer implements transparent persistence; persistent classes do not inherit any special base class or have to implement a special interface. Efficient fetching strategies and caching strategies are implemented transparently to the application.

9. What are the benefits of ORM and Hibernate?

There are many benefits from these. Out of which the following are the most important one.

i. Productivity – Hibernate reduces the burden of developer by providing much of the functionality and let the developer to concentrate on business logic.

ii. Maintainability – As hibernate provides most of the functionality, the LOC for the application will be reduced and it is easy to maintain. By automated object/relational persistence it even reduces the LOC.

iii. Performance – Hand-coded persistence provided greater performance than automated one. But this is not true all the times. But in hibernate, it provides more optimization that works all the time there by increasing the performance. If it is automated persistence then it still increases the performance.

iv. Vendor independence – Irrespective of the different types of databases that are there, hibernate provides a much easier way to develop a cross platform application.

Rajesh Raheja on Enterprise Software Development

My thoughts on Enterprise Software Technologies...and more.

Gilberto Holms

Java/SOA Architecture Blog

Universo Middleware

"Não é a agilidade da resposta que ficará marcada para sempre como o seu atributo mais forte, é a qualidade e a profundidade do que você está dizendo."

Enjoy IT - SOA, Java, Event-Driven Computing and Integration

Sharing my thoughts and experiences on SOA, Java in the Enterprise, Event-Driven Computing and Integration in the Enterprise

Oracle Technologies Premier

Technical posts on OSB/WLS/AIA, Oracle SOA Suite, BPM and Fusion Middleware

Java på svenska

Just another WordPress.com weblog

SOA Community Blog

by Jürgen Kress

Oracle .. Java .. OpenSource .. SOA

Just another WordPress.com weblog

Nitin's Oracle Fusion Middleware and SOA World

SOA FMW BPM BPEL OSB Governance J2EE and all the Geeky stuff

%d bloggers like this: