[Teneo] Custom support for Hibernate/JPA annotations [message #1404727] |
Tue, 05 August 2014 06:16  |
Eclipse User |
|
|
|
Hello,
Is it possible to add own support for Hibernate/JPA annotations not supported be Teneo? E.g.:
Code below is JPA/Hibernate annotations mapping with I would like to do in Teneo. I would like create custom sequence support for EmbeddedId (my own strategy : pl.postrowski.UserIdGenerator)
@Entity
public class User
{
@GeneratedValue( generator = GENERATOR_NAME )
@GenericGenerator( name = GENERATOR_NAME, strategy = "pl.postrowski.UserIdGenerator" )
@EmbeddedId
private UserId userId;
....
}
@Embeddable
public class UserId
{
private Long id;
private Long countryId;
}
1. In .ecore file:
For User:
<eClassifiers xsi:type="ecore:EClass" name="User" >
<eStructuralFeatures xsi:type="ecore:EReference" name="userId" lowerBound="1" eType="#//UserId" containment="true">
<eAnnotations source="teneo.jpa">
<details key="value" value="@GeneratedValue( generator = GENERATOR_NAME )"/>
</eAnnotations>
<eAnnotations source="teneo.jpa">
<details key="value" value="@GenericGenerator( name = GENERATOR_NAME, strategy = "pl.postrowski.UserIdGenerator" )"/>
</eAnnotations>
<eAnnotations source="teneo.jpa">
<details key="value" value="@EmbeddedId"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
For UserId:
<eClassifiers xsi:type="ecore:EClass" name="UserId">
<eAnnotations source="teneo.jpa">
<details key="value" value="@Embeddable"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="id" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//ELongObject" />
<eStructuralFeatures xsi:type="ecore:EAttribute" name="countryId" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//ELongObject"/>
</eClassifiers>
2. As a mapping result for EmdeddedId I was hoping it would be something like:
<composite-id access="org.eclipse.emf.teneo.hibernate.mapping.property.EReferencePropertyHandler" class="UserId" name="userId">
<meta attribute="eclassName" inherit="false">UserId</meta>
<key-property name="id" type="java.lang.Long">
<column name="`ID`" not-null="true" unique="false"/>
</key-property>
<key-property name="userId" type="java.lang.Long">
<column name="`USERID`" not-null="true" unique="false"/>
</key-property>
<generator class="pl.postrowski.UserIdGenerator"/>
</composite-id>
But <generator class="pl.postrowski.UserIdGenerator"/> is not generated. Can I add my own support/extension for Teneo to generate this part ?
Regards
Piotr
|
|
|
|
Re: [Teneo] Custom support for Hibernate/JPA annotations [message #1404985 is a reply to message #1404933] |
Wed, 06 August 2014 05:50  |
Eclipse User |
|
|
|
Hey Piotr,
On holiday, so a bit slower to respond, but this is indeed a fine/good way to do this.
gr. Martin
On 06-08-14 09:15, Piotr Ostrowski wrote:
> Ok, I solved this problem with extending TENEO:
>
>
> In app code :
>
> final HbEntityDataStore hbds = new HbEntityDataStore();
> final ExtensionManager extensionManager = hbds.getExtensionManager();
>
> extensionManager.registerExtension( ExtensionUtil.createExtension( IdMapper.class, UserIdMapper.class ) );
>
>
> Custom id mapper class:
>
> public class UserIdMapper extends IdMapper
> {
> @Override
> public void processEmbeddedId( PAnnotatedEReference aReference )
> {
> super.processEmbeddedId( aReference );
> Element eReferenceElement = getHbmContext().getCurrent();
> addSequeceForCompositeId( eReferenceElement );
> }
> private void addSequeceForCompositeId( Element eReferenceElement )
> {
> Element compositeIdElement = eReferenceElement.element( "composite-id" );
> if( compositeIdElement != null )
> {
> Element generatorElement = DocumentHelper.createElement( "generator" );
> generatorElement.addAttribute( "class", UserIdGenerator.class.getName() );
> compositeIdElement.add( generatorElement );
> }
> }
> }
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
|
|
|
Powered by
FUDForum. Page generated in 0.05115 seconds