[Teneo] Teneo Mapping XML file and Named Native Queries [message #1097462] |
Thu, 29 August 2013 15:11  |
Eclipse User |
|
|
|
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 #1098046 is a reply to message #1097593] |
Fri, 30 August 2013 10:28   |
Eclipse User |
|
|
|
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 10:46  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.45978 seconds