Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Teneo] Custom support for Hibernate/JPA annotations
[Teneo] Custom support for Hibernate/JPA annotations [message #1404727] Tue, 05 August 2014 10:16 Go to next message
Piotr Ostrowski is currently offline Piotr OstrowskiFriend
Messages: 4
Registered: August 2014
Location: Poznan
Junior Member
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 #1404933 is a reply to message #1404727] Wed, 06 August 2014 07:15 Go to previous messageGo to next message
Piotr Ostrowski is currently offline Piotr OstrowskiFriend
Messages: 4
Registered: August 2014
Location: Poznan
Junior Member
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 );
        }
    }
}    
Re: [Teneo] Custom support for Hibernate/JPA annotations [message #1404985 is a reply to message #1404933] Wed, 06 August 2014 09:50 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
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
Previous Topic:[EMFForms] Standalone rendering forms
Next Topic:[EEF] Suppress/filter properties in runtime
Goto Forum:
  


Current Time: Fri Apr 19 13:56:03 GMT 2024

Powered by FUDForum. Page generated in 0.02575 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top