Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] Teneo Mapping XML file and Named Native Queries
[Teneo] Teneo Mapping XML file and Named Native Queries [message #1097462] Thu, 29 August 2013 19:11 Go to next message
juan velez is currently offline juan velezFriend
Messages: 10
Registered: June 2013
Junior Member
I am kind of new to Teneo and I have been able to use it by making use of the Teneo Mapping XML File. A short example follows:

<?xml version="1.0" encoding="utf-8"?>
<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.eclipse.org/emft/teneo 
                        http://www.elver.org/xsd/teneo/persistence-mapping-hibernate.xsd">

    <epackage namespace-uri="http://eterra.com/market/refmdb">
        <eclass name="CommitStatus">
          <table name="etmCommitStatus" />
          <property name="commitStatus">
            <id/>
          </property>
        </eclass>
        <eclass name="DispatchStatus">
          <table name="etmDispatchStatus" />
          <property name="dispatchStatus">
            <id/>
          </property>
        </eclass>
        
        <!-- Core commercial model -->
        
        <!-- Participants (and def) -->
        <eclass name="Participant">
          <table name="etmParticipant" />
          <property name="participantId">
            <id/>
          </property>
        </eclass>
        <eclass name="ParticipantDef">
          <table name="etmParticipantDef" />
          <property name="key">
            <embedded-id/>
          </property>
          <property name="participant">
            <join-column name="participantId" insertable="false" updatable="false"/>
            <many-to-one />
          </property>
          <property name="effectiveTime">
              <column name="effectiveTime" insertable="false" updatable="false"/>
              <type type="com.eterra.commons.hibernate4.UTCJDateType" /> 
          </property>
          <property name="terminationTime">
              <type type="com.eterra.commons.hibernate4.UTCJDateType" /> 
          </property>
        </eclass>
        <eclass name="ParticipantDefKey">
          <property name="effectiveTime">
              <column name="effectiveTime" insertable="false" updatable="false"/>
              <type type="com.eterra.commons.hibernate4.UTCJDateType" /> 
          </property>
          <embeddable/>
        </eclass>
    </epackage>
</persistence-mapping>



I use PersistenceOptions.PERSISTENCE_XML to indicate this mapping file and I am able to use the entities in Hibernate HQL Queries and everything works well so far.

Now I need to add a native SQL Query but I do not know how to do that. I have looked at the documentation available with no luck. I also thought that since the XSD for the mapping is based on JPA, there would be a NamedNativeQuery(named-native-query) XML element/attribute but this is not available.

Any advice would be greatly appeciated
Re: [Teneo] Teneo Mapping XML file and Named Native Queries [message #1097593 is a reply to message #1097462] Thu, 29 August 2013 23:35 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Juan,
Hmmm, the NamedNativeQuery annotation is not supported by Teneo (I now see..). Can you enter a bugzilla for it? I can
add it sometime next week.
In the meantime, the xsd has a named-query element with the epackage/eclass elements.

Hope that helps...

gr. Martin

On 08/29/2013 09:11 PM, juan velez wrote:
> I am kind of new to Teneo and I have been able to use it by making use of the Teneo Mapping XML File. A short example
> follows:
>
>
> <?xml version="1.0" encoding="utf-8"?>
> <persistence-mapping xmlns="http://www.eclipse.org/emft/teneo"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://www.eclipse.org/emft/teneo
> http://www.elver.org/xsd/teneo/persistence-mapping-hibernate.xsd">
>
> <epackage namespace-uri="http://eterra.com/market/refmdb">
> <eclass name="CommitStatus">
> <table name="etmCommitStatus" />
> <property name="commitStatus">
> <id/>
> </property>
> </eclass>
> <eclass name="DispatchStatus">
> <table name="etmDispatchStatus" />
> <property name="dispatchStatus">
> <id/>
> </property>
> </eclass>
> <!-- Core commercial model -->
> <!-- Participants (and def) -->
> <eclass name="Participant">
> <table name="etmParticipant" />
> <property name="participantId">
> <id/>
> </property>
> </eclass>
> <eclass name="ParticipantDef">
> <table name="etmParticipantDef" />
> <property name="key">
> <embedded-id/>
> </property>
> <property name="participant">
> <join-column name="participantId" insertable="false" updatable="false"/>
> <many-to-one />
> </property>
> <property name="effectiveTime">
> <column name="effectiveTime" insertable="false" updatable="false"/>
> <type type="com.eterra.commons.hibernate4.UTCJDateType" /> </property>
> <property name="terminationTime">
> <type type="com.eterra.commons.hibernate4.UTCJDateType" /> </property>
> </eclass>
> <eclass name="ParticipantDefKey">
> <property name="effectiveTime">
> <column name="effectiveTime" insertable="false" updatable="false"/>
> <type type="com.eterra.commons.hibernate4.UTCJDateType" /> </property>
> <embeddable/>
> </eclass>
> </epackage>
> </persistence-mapping>
>
>
>
> I use PersistenceOptions.PERSISTENCE_XML to indicate this mapping file and I am able to use the entities in Hibernate
> HQL Queries and everything works well so far.
>
> Now I need to add a native SQL Query but I do not know how to do that. I have looked at the documentation available with
> no luck. I also thought that since the XSD for the mapping is based on JPA, there would be a
> NamedNativeQuery(named-native-query) XML element/attribute but this is not available.
> Any advice would be greatly appeciated


--

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
Re: [Teneo] Teneo Mapping XML file and Named Native Queries [message #1098046 is a reply to message #1097593] Fri, 30 August 2013 14:28 Go to previous messageGo to next message
juan velez is currently offline juan velezFriend
Messages: 10
Registered: June 2013
Junior Member
Hi Martin,

Yes, I will enter a bugzilla for it. Unfortunate I cannot use the named-query since this is the annotation used for HQL named queries, hence the need for the named-native-query as you pointed it out.

BTW, I had thought about a workaround, and maybe you can tell me if it will work:

Annotate one(any?) of the EClasses found in the ecore file with a teneo.jpa-sourced @NamedNativeQuery annotation. But I have the following questions:

- The (hibernate) documentation for the NamedNativeQuery annotation indicates that a resultclass needs to be provided, but since there is no really a class for it, how would that work? Would it be OK to just choose any, or would I need to create an EClass which maps directly to the result of my native sql query?

- Also, since the teneo hibernate mapping XML file is specifying which EClasses are really mapped and each EClass has a "table" property, what happens to the EClass I have chosen to add the @NativeNamedQuery annotation, since this is not really mapped to anything but a Native SQL Query?

Thank you
Re: [Teneo] Teneo Mapping XML file and Named Native Queries [message #1098058 is a reply to message #1098046] Fri, 30 August 2013 14:46 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Juan,
The annotations and the xml schema support the same annotations, so it is unsupported on the eclass also...

Yes in this case I think you have to create an eclass which reflects the result of the query. This is a normally mapped
eclass afaics.

Can't you create a database view and create an eclass for it? You can use the database view name as the name in the
table annotation, I think you can set attributes to tell hibernate to never update/insert anything for this eclass.

gr. Martin

On 08/30/2013 04:28 PM, juan velez wrote:
> Hi Martin,
>
> Yes, I will enter a bugzilla for it. Unfortunate I cannot use the named-query since this is the annotation used for HQL
> named queries, hence the need for the named-native-query as you pointed it out.
>
> BTW, I had thought about a workaround, and maybe you can tell me if it will work:
>
> Annotate one(any?) of the EClasses found in the ecore file with a teneo.jpa-sourced @NamedNativeQuery annotation. But I
> have the following questions:
>
> - The (hibernate) documentation for the NamedNativeQuery annotation indicates that a resultclass needs to be provided,
> but since there is no really a class for it, how would that work? Would it be OK to just choose any, or would I need to
> create an EClass which maps directly to the result of my native sql query?
>
> - Also, since the teneo hibernate mapping XML file is specifying which EClasses are really mapped and each EClass has a
> "table" property, what happens to the EClass I have chosen to add the @NativeNamedQuery annotation, since this is not
> really mapped to anything but a Native SQL Query?
>
> Thank you


--

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:[cdo] which class is responsible for deleting a model element
Next Topic:Force update of image/text after property change
Goto Forum:
  


Current Time: Mon Sep 23 16:35:41 GMT 2024

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

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

Back to the top