$jpa

Object providing a set of utility functions for JPA (Java Persistence API) code generation


Since : 2.0.7

Attributes and methods
.embeddedIdAnnotations(int leftMargin, AttributeInContext field) : String

Returns the JPA annotations for an 'embedded id' (with a left margin)
( there's no '@Id' for an embedded id )

Parameters :
   leftMargin : the left margin (number of blanks)
   field : the field to be annotated

Example :
   $jpa.embeddedIdAnnotations( 4, $field )

Since : 2.0.7

.entityAnnotations(int leftMargin, EntityInContext entity) : String

Returns a multiline String containing all the Java JPA annotations required for the current entity
with the given left marging before each line

Parameters :
   leftMargin : the left margin (number of blanks)
   entity : the entity to be annotated

Example :
   $jpa.entityAnnotations(4, $entity)

Since : 2.0.7

.fieldAnnotations(int leftMargin, AttributeInContext field) : String

Returns the JPA annotations for the given field (with a left margin)

Parameters :
   leftMargin : the left margin (number of blanks)
   field : the field to be annotated

Example :
   $jpa.fieldAnnotations( 4, $field )

Since : 2.0.7

.imports(EntityInContext entity) : List of 'String'

Returns a list of all the Java classes required by the current entity for JPA
( this version always returns 'javax.persistence.*' )

Parameters :
   entity : the entity

Example :
   #foreach( $import in $jpa.imports($entity) )
   import $import;
   #end

Since : 2.0.7

.linkAnnotations(int leftMargin, LinkInContext link, List alreadyMappedFields) : String

Returns a string containing all the JPA annotations for the given link
The list of mapped fields is used to determine if a JoinColumn is already mapped as a field
If a JoinColumn is based on a field already mapped then 'insertable=false, updatable=false' is set

Parameters :
   leftMargin : the left margin (number of blanks)
   link : the link to be annotated
   alreadyMappedFields : list of all the fields already mapped by JPA as 'simple fields'

Example :
   $jpa.linkAnnotations( 4, $link, $listOfMappedFields )

Since : 2.0.7