Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] OneToMany without join table in orm.xml
[Teneo] OneToMany without join table in orm.xml [message #630569] Mon, 04 October 2010 08:34 Go to next message
Peter Kullmann is currently offline Peter KullmannFriend
Messages: 199
Registered: July 2009
Senior Member
Hi, I'm just starting to use teneo with EclipseLink and tried to connect
my model to an existing legacy database. I have a simple 1:n relation
where the child table contains a column with the parent key to realize
the link in the db.

I tried some teneo.jpa annotations to control how the relation is
translated into the orm.xml but it always gives me the <join-table>
element as child of <one-to-many>. I've read about
teneo.mapping.join_table_for_non_contained_associations but how can I
set this option at "design time", ie when I try to create the orm.xml in
the context menu of the ecore.

Here's the ecore:
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="core"
nsURI="http:///ch/arenae/projectcontrolling/core.ecore"
nsPrefix="ch.arenae.projectcontrolling.core">
<eClassifiers xsi:type="ecore:EClass" name="Rapport">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="mitarbeiter"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute"
name="stundenVerrech" eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EDouble"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="id"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//ELong">
<eAnnotations source="teneo.jpa">
<details key="value"
value=" @Id&#xA;@GeneratedValue&#xA;@Column(name=&quot;R _ID&quot;) "/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="project"
lowerBound="1"
eType="#//Project" eOpposite="#//Project/rapporte">
<eAnnotations source="teneo.jpa">
<details key="value" value="@JoinColumn(name=&quot;P_ID&quot;)"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Project">
<eAnnotations source="teneo.jpa">
<details key="value" value="@Table(name=&quot;PROJEKTE&quot;)"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="id"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//ELong"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="rapporte"
upperBound="-1"
eType="#//Rapport" eOpposite="#//Rapport/project">
<eAnnotations source="teneo.jpa">
<details key="value" value="@OneToMany(unique=true,
indexed=false, mappedBy=&quot;project&quot;)"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
</ecore:EPackage>


And this is the generated orm.xml:

<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
http://java.sun.com/xml/ns/persistence/orm_1_0.xsd" version="1.0">
<persistence-unit-metadata>
<xml-mapping-metadata-complete/>
<persistence-unit-defaults>
<access>FIELD</access>
</persistence-unit-defaults>
</persistence-unit-metadata>
<entity class="ch.arenae.projectcontrolling.core.impl.RapportImpl"
name="Rapport">
<table name="RAPPORT"/>
<inheritance strategy="JOINED"/>
<attributes>
<id name="id">
<column insertable="true" length="255" name="R_ID"
nullable="true" precision="0" scale="0" unique="false" updatable="true"/>
<generated-value strategy="AUTO"/>
</id>
<basic fetch="EAGER" name="mitarbeiter" optional="true"/>
<basic fetch="EAGER" name="stundenVerrech" optional="true"/>
<basic name="eContainerFeatureID">
<column name="ECONT_FEAT_ID"/>
</basic>
<many-to-one fetch="EAGER" name="project" optional="true"
target-entity="ch.arenae.projectcontrolling.core.impl.ProjectImpl ">
<join-column insertable="true" name="P_ID" nullable="true"
unique="false" updatable="true"/>
<cascade>
<cascade-persist/>
<cascade-merge/>
<cascade-refresh/>
</cascade>
</many-to-one>
</attributes>
</entity>
<entity class="ch.arenae.projectcontrolling.core.impl.ProjectImpl"
name="Project">
<table name="PROJEKTE"/>
<inheritance strategy="JOINED"/>
<attributes>
<basic fetch="EAGER" name="id" optional="true"/>
<basic name="eContainerFeatureID">
<column name="ECONT_FEAT_ID"/>
</basic>
<one-to-many fetch="LAZY" mapped-by="project" name="rapporte"
target-entity="ch.arenae.projectcontrolling.core.impl.RapportImpl ">
<join-table name="PROJECT_RAPPORTE">
<join-column insertable="true" name="PROJECT_E_ID"
nullable="false" unique="false" updatable="true"/>
<inverse-join-column insertable="true" name="RAPPORT_ID"
nullable="false" unique="false" updatable="true"/>
</join-table>
<cascade>
<cascade-persist/>
<cascade-merge/>
<cascade-refresh/>
</cascade>
</one-to-many>
</attributes>
</entity>
</entity-mappings>

The goal is to create this:

<one-to-many fetch="LAZY" mapped-by="project" name="rapporte"
target-entity="ch.arenae.projectcontrolling.core.impl.RapportImpl ">
<join-table name="PROJECT_RAPPORTE">
</one-to-many>
(ie, no child elements)


Thanks & regards,
Peter
Re: [Teneo] OneToMany without join table in orm.xml [message #630576 is a reply to message #630569] Mon, 04 October 2010 08:42 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5340
Registered: July 2009
Senior Member
Hi Peter,
Where did you add the jpa annotations? In the ecore? If so then you need to regenerate the java code for Teneo to pick
up these changes.

Btw (I am not sure if I already mentioned this), but if you want to use EMF/Teneo in a non-rcp environment then it can
be an idea to try the EMFT Texo project (it has some benefits compared to EMF/Teneo in server side environments):
http://wiki.eclipse.org/Texo
http://wiki.eclipse.org/Texo#Code_generation_topics
http://wiki.eclipse.org/Texo#Texo_and_EMF

gr. Martin

On 10/04/2010 10:34 AM, Peter Kullmann wrote:
> Hi, I'm just starting to use teneo with EclipseLink and tried to connect
> my model to an existing legacy database. I have a simple 1:n relation
> where the child table contains a column with the parent key to realize
> the link in the db.
>
> I tried some teneo.jpa annotations to control how the relation is
> translated into the orm.xml but it always gives me the <join-table>
> element as child of <one-to-many>. I've read about
> teneo.mapping.join_table_for_non_contained_associations but how can I
> set this option at "design time", ie when I try to create the orm.xml in
> the context menu of the ecore.
>
> Here's the ecore:
> <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="core"
> nsURI="http:///ch/arenae/projectcontrolling/core.ecore"
> nsPrefix="ch.arenae.projectcontrolling.core">
> <eClassifiers xsi:type="ecore:EClass" name="Rapport">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="mitarbeiter"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="stundenVerrech"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EDouble"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="id"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//ELong">
> <eAnnotations source="teneo.jpa">
> <details key="value"
> value=" @Id&#xA;@GeneratedValue&#xA;@Column(name=&quot;R _ID&quot;) "/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EReference" name="project"
> lowerBound="1"
> eType="#//Project" eOpposite="#//Project/rapporte">
> <eAnnotations source="teneo.jpa">
> <details key="value" value="@JoinColumn(name=&quot;P_ID&quot;)"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Project">
> <eAnnotations source="teneo.jpa">
> <details key="value" value="@Table(name=&quot;PROJEKTE&quot;)"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="id"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//ELong"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="rapporte"
> upperBound="-1"
> eType="#//Rapport" eOpposite="#//Rapport/project">
> <eAnnotations source="teneo.jpa">
> <details key="value" value="@OneToMany(unique=true, indexed=false,
> mappedBy=&quot;project&quot;)"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
> </ecore:EPackage>
>
>
> And this is the generated orm.xml:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
> http://java.sun.com/xml/ns/persistence/orm_1_0.xsd" version="1.0">
> <persistence-unit-metadata>
> <xml-mapping-metadata-complete/>
> <persistence-unit-defaults>
> <access>FIELD</access>
> </persistence-unit-defaults>
> </persistence-unit-metadata>
> <entity class="ch.arenae.projectcontrolling.core.impl.RapportImpl"
> name="Rapport">
> <table name="RAPPORT"/>
> <inheritance strategy="JOINED"/>
> <attributes>
> <id name="id">
> <column insertable="true" length="255" name="R_ID" nullable="true"
> precision="0" scale="0" unique="false" updatable="true"/>
> <generated-value strategy="AUTO"/>
> </id>
> <basic fetch="EAGER" name="mitarbeiter" optional="true"/>
> <basic fetch="EAGER" name="stundenVerrech" optional="true"/>
> <basic name="eContainerFeatureID">
> <column name="ECONT_FEAT_ID"/>
> </basic>
> <many-to-one fetch="EAGER" name="project" optional="true"
> target-entity="ch.arenae.projectcontrolling.core.impl.ProjectImpl ">
> <join-column insertable="true" name="P_ID" nullable="true"
> unique="false" updatable="true"/>
> <cascade>
> <cascade-persist/>
> <cascade-merge/>
> <cascade-refresh/>
> </cascade>
> </many-to-one>
> </attributes>
> </entity>
> <entity class="ch.arenae.projectcontrolling.core.impl.ProjectImpl"
> name="Project">
> <table name="PROJEKTE"/>
> <inheritance strategy="JOINED"/>
> <attributes>
> <basic fetch="EAGER" name="id" optional="true"/>
> <basic name="eContainerFeatureID">
> <column name="ECONT_FEAT_ID"/>
> </basic>
> <one-to-many fetch="LAZY" mapped-by="project" name="rapporte"
> target-entity="ch.arenae.projectcontrolling.core.impl.RapportImpl ">
> <join-table name="PROJECT_RAPPORTE">
> <join-column insertable="true" name="PROJECT_E_ID" nullable="false"
> unique="false" updatable="true"/>
> <inverse-join-column insertable="true" name="RAPPORT_ID"
> nullable="false" unique="false" updatable="true"/>
> </join-table>
> <cascade>
> <cascade-persist/>
> <cascade-merge/>
> <cascade-refresh/>
> </cascade>
> </one-to-many>
> </attributes>
> </entity>
> </entity-mappings>
>
> The goal is to create this:
>
> <one-to-many fetch="LAZY" mapped-by="project" name="rapporte"
> target-entity="ch.arenae.projectcontrolling.core.impl.RapportImpl ">
> <join-table name="PROJECT_RAPPORTE">
> </one-to-many>
> (ie, no child elements)
>
>
> Thanks & regards,
> Peter


--

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@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] OneToMany without join table in orm.xml [message #630813 is a reply to message #630576] Tue, 05 October 2010 07:26 Go to previous messageGo to next message
Peter Kullmann is currently offline Peter KullmannFriend
Messages: 199
Registered: July 2009
Senior Member
Hi Martin

I tried again and the annotations were not picked up in the sense I
wanted them. If I understand correctly it is rather difficult to
generate the orm.xml from an ecore via the generated EMF code and even
more difficult to tweak the generation. One of the problems would be the
fact that EMF generates interfaces and that jpa annotations on
interfaces seem to have some difficulties.

I can see that Texo should be easier. So, I'm trying this.

Thanks,
Peter


Martin Taal schrieb:
> Hi Peter,
> Where did you add the jpa annotations? In the ecore? If so then you need
> to regenerate the java code for Teneo to pick up these changes.
>
> Btw (I am not sure if I already mentioned this), but if you want to use
> EMF/Teneo in a non-rcp environment then it can be an idea to try the
> EMFT Texo project (it has some benefits compared to EMF/Teneo in server
> side environments):
> http://wiki.eclipse.org/Texo
> http://wiki.eclipse.org/Texo#Code_generation_topics
> http://wiki.eclipse.org/Texo#Texo_and_EMF
>
> gr. Martin
>
Re: [Teneo] OneToMany without join table in orm.xml [message #635512 is a reply to message #630813] Wed, 27 October 2010 07:26 Go to previous message
Peter Kullmann is currently offline Peter KullmannFriend
Messages: 199
Registered: July 2009
Senior Member
It works now: I have to generate the orm.xml programatically (as is
explained in http://wiki.eclipse.org/Teneo/EclipseLink):

final Properties props = new Properties();
props.setProperty(
PersistenceOptions.JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS ,
"false");
final ORMGenerator converter = new ORMGenerator();
final String orm = converter.generateORM(
new EPackage[] { CorePackage.eINSTANCE },
converter.getDefaultPersistenceOptions(props));
System.err.println(orm);

Regards,
Peter


Peter Kullmann schrieb:
> Hi Martin
>
> I tried again and the annotations were not picked up in the sense I
> wanted them. If I understand correctly it is rather difficult to
> generate the orm.xml from an ecore via the generated EMF code and even
> more difficult to tweak the generation. One of the problems would be the
> fact that EMF generates interfaces and that jpa annotations on
> interfaces seem to have some difficulties.
>
> I can see that Texo should be easier. So, I'm trying this.
>
> Thanks,
> Peter
>
>
> Martin Taal schrieb:
>> Hi Peter,
>> Where did you add the jpa annotations? In the ecore? If so then you
>> need to regenerate the java code for Teneo to pick up these changes.
>>
>> Btw (I am not sure if I already mentioned this), but if you want to
>> use EMF/Teneo in a non-rcp environment then it can be an idea to try
>> the EMFT Texo project (it has some benefits compared to EMF/Teneo in
>> server side environments):
>> http://wiki.eclipse.org/Texo
>> http://wiki.eclipse.org/Texo#Code_generation_topics
>> http://wiki.eclipse.org/Texo#Texo_and_EMF
>>
>> gr. Martin
>>
Previous Topic:How to display property sheet from explorer based on eobject.
Next Topic:Links in http://wiki.eclipse.org/Teneo/EclipseLink
Goto Forum:
  


Current Time: Sun Dec 21 22:20:47 GMT 2014

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

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