![]() | ![]() |
![]() |
| Project | Ver 1.1 | Ver 1.2 | JDO | JPA | Guides | Tools |
| 1.1 | Preparation | O/R Mapping | Runtime | Extensions | Developer |
![]() One of the things that JDK 1.5 provides that can be of some use to JPOX is annotations. JPOX provides a level of support for JDO annotations from JPOX version 1.1.2 onwards and this support is currently considered experimental work-in-progress so please report any issues found. Things to bear in mind when considering using this facility
The principal idea behind annotations in JPOX is that you can store the basic persistence information that you embody in a JDO MetaData file instead in the Java file alongside the fields of the class. We do not recommend storing the information storable in an ORM MetaData file as annotations since this is the type of information that you would typically change at deployment time to match the RDBMS in use etc. Some general rules for annotations are
Let's start with some sample classes, and add some annotations.
public class Person
{
String firstName;
String lastName;
public String getFirstName()
{
return firstName;
}
public String getLastName()
{
return lastName;
}
}
public class Manager extends Person
{
HashSet employees;
Department department;
public Department getDepartment()
{
return department;
}
}So we firstly want to mark Person and Manager as persistent. We do this using the @PersistenceCapable annotation.
@PersistenceCapable
public class Person
{
...
}
@PersistenceCapable
public class Manager extends Person
{
...
}Now that we know our classes are going to be persisted ("PersistenceCapable") we need to configure how the fields will be persisted. By default our simple fields like "firstName", "lastName" will be persisted, but we can reenforce this using the @Field annotation
@PersistenceCapable
public class Person
{
@Field
String firstName;
@Field
String lastName;
...
}We should point out that we could have added the annotations to the "getter" method instead of the field itself. Both places serve the same purpose. Next we want to configure that our Person and Manager classes each have their own table. We use the @Inheritance annotation
@PersistenceCapable
@Inheritance(strategy=InheritanceStrategyType.NEW_TABLE)
public class Person
{
...
}
@PersistenceCapable
@Inheritance(strategy=InheritanceStrategyType.NEW_TABLE)
public class Manager extends Person
{
...
}
Enhancing the annotated classes operates in a very similar way as enhancing a normal class with MetaData except that you supply the class files and not MetaData files to JPOX Enhancer.
Generating the schema for annotated classes operates in a very similar way as generating the schema for a normal class with MetaData except that you supply the class files and not MetaData files to JPOX SchemaTool.
This section lists the JDO annotations supported by JPOX.
Until we have time to provide full docs on these annotations please refer to the
|