EJB3 Annotation examples
- Annotations on EDataType
- ManyToMany Annotations
- Inheritance and Discriminator Annotations
- Other examples
Annotations on EDataType
An example of the use of a Table annotation at EClass level and Column annotations on EDataType level, first in xml and then using the :
<epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/edatatype_column"> <eclass name="Book"> <table name="mybooktable"/> <property name="title"> <column name="titel" unique="true" length="25"/> </property> </eclass> <edatatype name="TitleType"> <column name="mytitle" unique="false" length="50"/> </edatatype> <edatatype name="PagesType"> <column updatable="false" insertable="false"/> </edatatype> <edatatype name="WeightType"> <column name="gewicht" nullable="true" precision="5" scale="2"/> </edatatype> </epackage>
And in java annotation syntax in EAnnotations:
<xsd:complexType name="Book"> <xsd:annotation> <xsd:appinfo source="teneo.jpa">@Table(name="mybooktable")</xsd:appinfo> </xsd:annotation> <xsd:sequence> <xsd:element name="title" type="TitleType"> <xsd:annotation> <xsd:appinfo source="teneo.jpa">@Column(name="titel" unique="true" length="25")</xsd:appinfo> </xsd:annotation> </xsd:element> <xsd:element name="pages" type="PagesType"/> <xsd:element name="weight" type="WeightType"/> <xsd:element name="author" type="xsd:string"/> </xsd:sequence> </xsd:complexType> <xsd:simpleType name="TitleType"> <xsd:annotation> <xsd:appinfo source="teneo.jpa">@Column(name="mytitle" unique="false" length="50")</xsd:appinfo> </xsd:annotation> <xsd:restriction base="xsd:string"> </xsd:restriction> </xsd:simpleType> <xsd:simpleType name="PagesType"> <xsd:annotation> <xsd:appinfo source="teneo.jpa">@Column(updatable="false" insertable="false")</xsd:appinfo> </xsd:annotation> <xsd:restriction base="xsd:int"> </xsd:restriction> </xsd:simpleType> <xsd:simpleType name="WeightType"> <xsd:annotation> <xsd:appinfo source="teneo.jpa">@Column(name="gewicht" nullable="true" precision="5" scale="2")</xsd:appinfo> </xsd:annotation> <xsd:restriction base="xsd:decimal"> </xsd:restriction> </xsd:simpleType>
ManyToMany Annotations
An example of the use of a ManyToMany annotation:
<xsd:complexType name="Cntr">
<xsd:sequence>
<xsd:element name="rght" type="xsd:IDREF" ecore:reference="this:Rght" maxOccurs="unbounded" ecore:opposite="cntr">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@ManyToMany(fetch=EAGER cascade={MERGE PERSIST} targetEntity="Rght" indexed="false")
@JoinTable(name="RightCenter")
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="lft" type="xsd:IDREF" ecore:reference="this:Lft" maxOccurs="unbounded" ecore:opposite="cntr">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@ManyToMany(fetch=EAGER cascade={MERGE PERSIST} targetEntity="Lft")
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Lft">
<xsd:sequence>
<xsd:element name="cntr" type="xsd:IDREF" ecore:reference="this:Cntr" maxOccurs="unbounded" ecore:opposite="lft">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@ManyToMany(fetch=LAZY cascade={MERGE PERSIST} targetEntity="Cntr" mappedBy="lft")
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Rght">
<xsd:sequence>
<xsd:element name="cntr" type="xsd:IDREF" ecore:reference="this:Cntr" maxOccurs="unbounded" ecore:opposite="rght">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@ManyToMany(fetch=LAZY cascade={MERGE PERSIST} targetEntity="Cntr" mappedBy="rght" indexed="false")
@JoinTable(name="RightCenter")
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
Inheritance and Discriminator Annotations
An example of the use of an Inheritance and Discriminator related annotations:
<xsd:complexType name="Price">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@Table(name="myprice")
@Inheritance(strategy=SINGLE_TABLE)
@DiscriminatorColumn(name="DISCRIMINATOR" discriminatorType=STRING)
@DiscriminatorValue("myPrice")
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="value" type="xsd:decimal"/>
</xsd:sequence>
</xsd:complexType>
In xml:
<eclass name="Price"> <table name="myprice" /> <inheritance>SINGLE_TABLE</inheritance> <discriminator-column name="DISCRIMINATOR" discriminator-type="STRING" /> <discriminator-value>myPrice</discriminator-value> </eclass>
Other examples
For other examples of annotations on this site see here: Inheritance and Associations.

