| Java, Eclipse and Web programming Tutorials |
Version 0.1
Copyright © 2009 Lars Vogel
07.07.2009
| Revision History | ||
|---|---|---|
| Revision 0.1 | 07.07.2009 | Lars Vogel |
| Created | ||
Table of Contents
This article describes Eclipse Dali and does not give a general introduction into JPA. Please see Java Persistence API (JPA) with EclipseLink- Tutorial for an introduction.
To use Eclipse Dali you also need Eclipse DTP which is described in Eclipse DTP Tutorial
To use Eclipse Dali you also need Derby which is described in Eclipse DTP Tutorial or independently of Eclipse in Apache Derby .
Use the update manager to install from "Web, XML, and Java Development" the "Dali Java Persistence Tools" and "Dali Java Persistence Tools - EclipseLink Support (Optional)". Install also "EclipseLink JPA" from "EclipseRT Target Platform Components". .
Please see Using the Eclipse Update Manager .
Create a new project "de.vogella.dali.first" via File -> New -> Others -> JPA -> JPA Project.

Click twice next.

The JPA perspective should now be opened.
Create a package "de.vogella.dali.first".
Select File -> New -> Other -> JPA -> Entity and create the following class.

package de.vogella.dali.first;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
/**
* Entity implementation class for Entity: Person
*
*/
@Entity
public class Person implements Serializable {
@Id
private int id;
private String firstName;
private String lastName;
private static final long serialVersionUID = 1L;
public Person() {
super();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
Annotate now the class with @Entity (before the class name". This will activate the views "JPA Structure" and "JPA Details".

You can now use the right mouse button in the "JPA Structure" view to map your elements.

Now you can use the "JPA Details" view to define for example how the primatry keys should get defined, e.g. via a sequence "SEQUENCE".

Thank you for practicing with this tutorial.
Please note that I maintain this website in my private time. If you like the information I'm providing please help me by donating.For questions and discussion around this article please use the www.vogella.de Google Group. Also if you note an error in this article please post the error and if possible the correction to the Group.
I believe the following is a very good guideline for asking questions in general and also for the Google group How To Ask Questions The Smart Way.
http://www.vogella.de/code/codeeclipse.html Source Code of Examples