Search This Blog

Showing posts with label JPA. Show all posts
Showing posts with label JPA. Show all posts

Tuesday, 5 November 2013

Components in JPA

We have used components in Hibernate. They provide a very good technique for code reuse. They are also useful if we do now want to represent a particular table as Entity and give them their own separate life cycle. JPA also provides support for components.

Tuesday, 15 October 2013

Saving an Enum in JPA

Consider the below entity:
@Entity
@Table(name = "STUDENT")
public class Student {
 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 private Long id;

Saturday, 14 September 2013

Hibernate's custom annotations

In the previous few posts we saw how JPA provides us with an annotation driven approach to configure our entities. As with all standard APIs, when vendors implemented JPA, they found that the annotations did not cover every nifty trick provided by the implementations.

Monday, 5 August 2013

Excluding a property from the ORM framework

If we have a property that does not map to any column in the table, we simply do not specify that property in our hbm files. But with JPA annotations it is a little different. A class if marked with an Entity annotation, all its properties are considered persistent by default. So how do we exclude a property ?

Saturday, 6 July 2013

@Column

In the previous post we saw several of the JPA annotations. The one that occurs most commonly is the Column annotation can be used without any attributes.

Monday, 17 June 2013

JPA's GenerationType.TABLE

In the previous posts we saw the identifier generation strategies supported by JPA and their equivalent ones in Hibernate. There is however one in JPA - The TABLE GenerationType that is not there in Hibernate API. I decided to look at the same.

Monday, 10 June 2013

@GeneratedValue

In our previous posts we saw how the GeneratedValue annotation was used to specify the identifier generator strategy. I decided to look at the various options available in detail

Thursday, 2 May 2013

Simple Annotated Entity

In an earlier post when working with Hibernate I tried to generate an hbm with minimal content. I decided to try something similar with JPA. The minimum annotations needed to work with a simple table.

Saturday, 6 April 2013

Setting schema information

In all my posts on JPA I have used a PostgreSQL database. The database is composed of multiple schemas (Unlike PostgreSQL, MySQL database supports only a single schema). So we need to specify to our application the schema being used. I did that by setting the schema attribute of the Table annotation.

Sunday, 24 March 2013

First Look at JPA Annotations

In the earlier posts we saw how to run a JPA application. I decided to have a look at the annotations used in the previous examples.

Tuesday, 19 March 2013

persistence.xml

In previous post we have seen the persistence.xml file - the file provides all the configuration information needed to get JPA up and running. We also saw that the JPA standard is very particular of the location of the file.

Thursday, 14 March 2013

My First JPA Application - 3

In the last two posts we setup the code to run a simple JPA example. In this post I shall now test out the code. The code to execute is as below:

Wednesday, 13 March 2013

My First JPA Application - 2

In the previous post I created  the project structure for my JPA application. Now to look deeper into the code. I decided to build a simple Pet-Owner relation. One owner can have multiple pets. The java classes for the same is as below:

Tuesday, 12 March 2013

My First JPA Application

Till date I have always worked with Hibernate's native API. All my projects involved the SessionFactory, Session and other Hibernate APIs. And it works great. So why should I be looking at JPA ?