# Castor JDO - Support for the JPA specification

## JPA annotations - Motivation

It has always been a goal of the Castor JDO project to eventually fully support the JPA specification and become a first class JPA provider that can e.g. be easily integrated with Spring ORM. Whilst full compliance is still work in progress, there are several small areas where sufficient progress has been made, and where partial support will be made available to the user community.

One such area is (partial) support for JPA annotations. This chapter highlights how JPA-annotated Java classes can be used with Castor JDO to persist such classes through the existing persistence framework part of Castor, without little additional requirements.

The following sections describe ...

1. The prerequisites.

2. The current limitations.

3. The supported JPA annotations.

4. How to use Castor JDO to persist JPA-annotated classes.

5. How to use Castor JDO as Spring ORM provider to persist JPA-annotated classes.

## Prerequisites and outline

The following sections assume that you have a (set of) JPA-annotated domain classes which you would like to persist using Castor JDO.

As such, we explain how to enlist those classes with Castor JDO (through the JDOClassDescriptorResolver interface, so that Castor JDO will be able to find and work with your JPA-annotated classes. In addition, we explain how to achieve the same with Spring ORM and the Spring ORM provider for Castor JDO.

By the end of this chapter is should become obvious that Castor JDO is well-prepared to integrate with the annotation part of the JPA specification, although support for JPA annotations is currently limited.

## Limitations and Basic Information

### persistence.xml

In Castor JPA there is no use or support for a JPA `persistence.xml` configuration file for now. All required configuration needs to be supplied by one of the following means:

- Castor JDO configuration file.

- JDOClassDescriptorResolver configuration.

- Spring configuration file for the Spring ORM provider for Castor JDO.

### JPA access type and the placing of JPA annotations

Because Castor does not support direct field access, this feature is not supported by Castor JPA. Thus all annotations have to be defined on the getter methods of the fields. If JPA related annotations are found on fields, Castor will throw an exception.

### Primary Keys

Primary keys made of single fields are supported by Castor as defined in the JPA specification (through the use of the `@Id` annotation). If you need to define composite primary keys, please note that that Castor does not support relations with composite primary keys.

If you still want to persist single classes with the use of composite primary keys, none of the available JPA annotations (`@EmbeddedId` or `@IdClass`) is supported as such. Instead Castor uses a kind of ad-hoc `IdClass` mechanism. Simply define multiple `@Id` annotations on the fields that make up your composite primary key, and Castor JDO will internally create the relevant constructs.

### Inheritance, mapped superclasses, etc.

These JPA annotations are currently not supported by Castor JDO. For now, you can only define entities.

### Relations

Besides the fact, that Castor does not support composite primary keys in relations, there are some limitations on the different kinds of relations between entities. For detailed information, please read the documentation about the different relations types further below.