Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "CDO/Hibernate Store/Model Relational Mapping"
(New page: __TOC__ The CDO Hibernate Store can use Teneo for the Model Relational mapping. Teneo generates a mapping for Hibernate on the basis of the ecore model...) |
|||
Line 18: | Line 18: | ||
JPA Annotations with a TYPE target can be used for EMF EClasses, annotations with METHOD and FIELD targets can be used for EStructuralFeatures. Note: JPA annotations relevant for a non-reference type java member can also be set on an EDataType. | JPA Annotations with a TYPE target can be used for EMF EClasses, annotations with METHOD and FIELD targets can be used for EStructuralFeatures. Note: JPA annotations relevant for a non-reference type java member can also be set on an EDataType. | ||
+ | === JPA Annotations as EAnnotations === | ||
The EAnnotations should adhere to the following format: | The EAnnotations should adhere to the following format: | ||
* The source must be: '''teneo.jpa'''. You can also configure your own annotation source, see Teneo documentation for details. | * The source must be: '''teneo.jpa'''. You can also configure your own annotation source, see Teneo documentation for details. | ||
* The key must be: '''appinfo''' or '''value''' | * The key must be: '''appinfo''' or '''value''' | ||
− | + | The page: [[CDO_Hibernate_Store_Annotation_Examples#Examples_of_annotations_defined_in_Ecore_or_in_a_XML_Schema_model|here]] contains examples of JPA eannotations in Ecore or in a XML Schema file. | |
+ | === JPA Annotations in XSD, some examples=== | ||
+ | |||
+ | This annotation sets the [[Teneo/Hibernate/ModelRelational/Inheritance_Mapping|inheritance mapping]] strategy for the Address to joined: | ||
+ | <source lang="xml"> | ||
+ | <xsd:complexType name="Address" abstract="true"> | ||
+ | <xsd:annotation> | ||
+ | <xsd:appinfo source="teneo.jpa">@Inheritance(strategy=JOINED)</xsd:appinfo> | ||
+ | </xsd:annotation> | ||
+ | <xsd:sequence> | ||
+ | <xsd:element name="name" type="xsd:string"/> | ||
+ | </xsd:sequence> | ||
+ | </xsd:complexType> | ||
+ | </source> | ||
+ | |||
+ | The following annotation specifies that the association does not need an index column: | ||
+ | <source lang="xml"> | ||
+ | <xsd:element name="containedItem" type="this:ContainedItem" maxOccurs="unbounded"> | ||
+ | <xsd:annotation> | ||
+ | <xsd:appinfo source="teneo.jpa">@OneToMany(indexed=false)</xsd:appinfo> | ||
+ | </xsd:annotation> | ||
+ | </xsd:element> | ||
+ | </source> | ||
+ | |||
+ | === JPA Annotations in the Ecore Model Editor === | ||
+ | To set an annotation in the ecore model using the Ecore Model Editor do the following: | ||
+ | # open the model in the editor | ||
+ | # right click on the model element (EClass, EStructuralFeature, etc.) on which you want to set a JPA annotation | ||
+ | # do: New Child > EAnnotation | ||
+ | # check in the properties view, there are two fields for the new EAnnotation: references and source. Set source to: teneo.jpa | ||
+ | # right click on the new EAnnotation in the ecore model editor and do: New Child > Details Entry | ||
+ | # click on the new detail entry, the properties view shows a key and value field. Enter the word 'value' in the key field and in the value field enter your annotation, for example: @Id or @Basic. Just as you would set it in Java. | ||
---- | ---- | ||
Wikis: [[CDO]] | [[Net4j]] | [[EMF]] | [[Eclipse]] | Wikis: [[CDO]] | [[Net4j]] | [[EMF]] | [[Eclipse]] |
Revision as of 16:50, 21 January 2010
Contents
The CDO Hibernate Store can use Teneo for the Model Relational mapping. Teneo generates a mapping for Hibernate on the basis of the ecore model and optional JPA annotations. JPA annotations can be specified directly in the model or in a separate xml.
Teneo supports all JPA annotations and many Hibernate extensions.
Annotations Format
The Teneo documentation has a detailed description of the format in which annotations can be specified. The main points are summarized here:
Teneo allows two ways to specify EJB3/JPA-like annotations:
- using the java annotations syntax in EAnnotations (ecore and xsd) (examples)
- a separate xml document (examples).
This page shows examples of both approaches.
JPA Annotations with a TYPE target can be used for EMF EClasses, annotations with METHOD and FIELD targets can be used for EStructuralFeatures. Note: JPA annotations relevant for a non-reference type java member can also be set on an EDataType.
JPA Annotations as EAnnotations
The EAnnotations should adhere to the following format:
- The source must be: teneo.jpa. You can also configure your own annotation source, see Teneo documentation for details.
- The key must be: appinfo or value
The page: here contains examples of JPA eannotations in Ecore or in a XML Schema file.
JPA Annotations in XSD, some examples
This annotation sets the inheritance mapping strategy for the Address to joined:
<xsd:complexType name="Address" abstract="true"> <xsd:annotation> <xsd:appinfo source="teneo.jpa">@Inheritance(strategy=JOINED)</xsd:appinfo> </xsd:annotation> <xsd:sequence> <xsd:element name="name" type="xsd:string"/> </xsd:sequence> </xsd:complexType>
The following annotation specifies that the association does not need an index column:
<xsd:element name="containedItem" type="this:ContainedItem" maxOccurs="unbounded"> <xsd:annotation> <xsd:appinfo source="teneo.jpa">@OneToMany(indexed=false)</xsd:appinfo> </xsd:annotation> </xsd:element>
JPA Annotations in the Ecore Model Editor
To set an annotation in the ecore model using the Ecore Model Editor do the following:
- open the model in the editor
- right click on the model element (EClass, EStructuralFeature, etc.) on which you want to set a JPA annotation
- do: New Child > EAnnotation
- check in the properties view, there are two fields for the new EAnnotation: references and source. Set source to: teneo.jpa
- right click on the new EAnnotation in the ecore model editor and do: New Child > Details Entry
- click on the new detail entry, the properties view shows a key and value field. Enter the word 'value' in the key field and in the value field enter your annotation, for example: @Id or @Basic. Just as you would set it in Java.