Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo+EMF] Meet-in-the-Middle mapping
[Teneo+EMF] Meet-in-the-Middle mapping [message #517942] Tue, 02 March 2010 15:11 Go to next message
Sudeep is currently offline SudeepFriend
Messages: 7
Registered: March 2010
Junior Member
Hi,

Before I start, I wish to confess, I'm a newbie in EMF (Please correct me if I'm wrong).

Let me briefly describe the situation:

PostgreSQL server is running at the backend with an already existing database in it, on one hand.

On the other hand, I have been given 8 EPackages as 8 .ecore files with each depending on each other.

Until now I found Teneo offering choices like 1)using Hibernate with .hbm.xml file, 2)using Eclipselink with orm.xml file, 3)using CDO+teneo with <persistence-mapping>, to map with the database.

I have a feeling (from some teneo tutorials I tried) that all these choices, creates its own tables for appropriate EClasses in the database rather than giving us control to perform mapping between an EClass and an 'Existing' table in a database.

Is there a technique for doing meet-in-the-middle mapping from teneo?
If they are available,
1)Is it possible to apply that technique for the situation I hinted before?
2)Is there an example or tutorial I can find?


cheers,
Sudeep
Re: [Teneo+EMF] Meet-in-the-Middle mapping [message #517956 is a reply to message #517942] Tue, 02 March 2010 15:22 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Sudeep,
Teneo is mostly for top-down mapping. You can generate a hbm.xml/orm.xml file quite easily and then customize it to fit
to the database schema you currently have. But this is a manual task and currently not supported by tooling.

gr. Martin

Sudeep wrote:
> Hi,
>
> Before I start, I wish to confess, I'm a newbie in EMF (Please correct
> me if I'm wrong).
>
> Let me briefly describe the situation:
>
> PostgreSQL server is running at the backend with an already existing
> database in it, on one hand.
>
> On the other hand, I have been given 8 EPackages as 8 .ecore files with
> each depending on each other.
>
> Until now I found Teneo offering choices like 1)using Hibernate with
> .hbm.xml file, 2)using Eclipselink with orm.xml file, 3)using CDO+teneo
> with <persistence-mapping>, to map with the database.
> I have a feeling (from some teneo tutorials I tried) that all these
> choices, creates its own tables for appropriate EClasses in the database
> rather than giving us control to perform mapping between an EClass and
> an 'Existing' table in a database.
>
> Is there a technique for doing meet-in-the-middle mapping from teneo?
> If they are available, 1)Is it possible to apply that technique for the
> situation I hinted before? 2)Is there an example or tutorial I can find?


--

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+EMF] Meet-in-the-Middle mapping [message #518218 is a reply to message #517956] Wed, 03 March 2010 14:06 Go to previous messageGo to next message
Sudeep is currently offline SudeepFriend
Messages: 7
Registered: March 2010
Junior Member
Hello Martin,

Thanks for the reply. Well, I tried like you said; in this case, I have an existing database with less than 150 Tables in it.

For simplicity, I just picked one table called 'users' which was created with the following:
CREATE TABLE users
(
dtype character varying(31) NOT NULL,
id bigint NOT NULL,
active boolean,
autologin boolean NOT NULL,
... ... ...
firstname character varying(255),
lastname character varying(255),
... ... ...
e_id bigint,
CONSTRAINT users_pkey PRIMARY KEY (id),
... ... ...
)

On the other side, from the 8 ecore file's generated *.impl java packages, I picked one implementation class
public class NaturalPersonImpl extends EObjectImpl implements NaturalPerson {

I just planned to map the column 'firstname' in 'users' table with the 'firstName' attribute of the implementation class 'NaturalPersonImpl'


Selecting all the 8 ecore files, I generated a *.hbm file which had a big pile of mappings in it. As mentioned above, for simplicity, I just picked the
NaturalPersonimpl and its parent class from the generated-hbm.xml altered a bit which look like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping schema="public" auto-import="false">

<class name="foundation.IdentifiableElement" entity-name="IdentifiableElement" abstract="true" lazy="false" discriminator-value="IdentifiableElement">
<meta attribute="eclassName">IdentifiableElement</meta>
<meta attribute="epackage">http://foundation/1.0</meta>
<id type="long" name="e_id" column="e_id" access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
<meta attribute="syntheticId">true</meta>
<generator class="native"/>
</id>
<discriminator type="string">
<column name="dtype" index="identifiableelementdtype" length="255" not-null="true"/>
</discriminator>
<version name="e_version" column="e_version" access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
<meta attribute="syntheticVersion">true</meta>
</version>
<property name="guid" lazy="false" insert="true" update="true" not-null="true" unique="false" type="java.lang.String">
<column not-null="true" unique="false" name="`guid`"/>
</property>
<property name="namespace" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
<column not-null="false" unique="false" name="`namespace`"/>
</property>
</class>


<subclass name="foundation.impl.NaturalPersonImpl" entity-name="NaturalPerson" abstract="false" lazy="false" extends="IdentifiableElement" discriminator-value="NaturalPerson">
<meta attribute="eclassName">NaturalPerson</meta>
<meta attribute="epackage">http://foundation/1.0</meta>
<join table="`users`">
<key column="e_id"/>
<property name="firstName" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
<column not-null="false" unique="false" name="`firstname`"/>
</property>
</join>
</subclass>

</hibernate-mapping>

With the .cfg.xml file configured, I ran the code:

Transaction tx = null;
Session session = SessionFactoryUtil.getInstance().openSession();

Query query = session.createQuery("SELECT s FROM NaturalPerson s");
List<NaturalPerson> natp1 = query.list();
NaturalPerson natp2 = natp1.get(1);
System.out.println(natp2.getFirstName());

This threw me an error as follows:

03.03.2010 14:29:34 org.slf4j.impl.JCLLoggerAdapter info
INFO: Hibernate Annotations 3.4.0.GA
03.03.2010 14:29:34 org.slf4j.impl.JCLLoggerAdapter info
INFO: Hibernate 3.3.2.GA
... ... ... ...
INFO: Configuration resource: /hibernate.cfg.xml
03.03.2010 14:29:34 org.slf4j.impl.JCLLoggerAdapter info
INFO: Reading mappings from resource : com/sap/usdl3/queries/hibernate.hbm.xml
... ... ... ...
INFO: using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost:5432/cdoago
03.03.2010 14:29:35 org.slf4j.impl.JCLLoggerAdapter info
... ... ... ...
INFO: schema update complete
Hibernate: select naturalper0_.e_id as e1_0_, naturalper0_.e_version as e3_0_, naturalper0_."guid" as guid4_0_, naturalper0_."namespace" as namespace5_0_, naturalper0_1_."firstname" as firstname2_1_ from public.IdentifiableElement naturalper0_ inner join public."users" naturalper0_1_ on naturalper0_.e_id=naturalper0_1_.e_id where naturalper0_.dtype='NaturalPerson'
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:546)
at java.util.ArrayList.get(ArrayList.java:321)
at foundation.impl.CoreTesting.updateService(CoreTesting.java:4 1)
at foundation.impl.CoreTesting.main(CoreTesting.java:31)


Any idea would be helpful.


cheers,
Sudeep
Re: [Teneo+EMF] Meet-in-the-Middle mapping [message #518232 is a reply to message #518218] Wed, 03 March 2010 14:39 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Sundeep,
And when you execute this sql directly then you get results?
select naturalper0_.e_id as e1_0_, naturalper0_.e_version as e3_0_, naturalper0_."guid" as guid4_0_,
naturalper0_."namespace" as namespace5_0_, naturalper0_1_."firstname" as firstname2_1_ from public.IdentifiableElement
naturalper0_ inner join public."users" naturalper0_1_ on naturalper0_.e_id=naturalper0_1_.e_id where
naturalper0_.dtype='NaturalPerson'

Also (not directly related to this issue I think), to be sure, the session factory is created using a Teneo datastore,
right?

gr. Martin

Sudeep wrote:
> Hello Martin,
>
> Thanks for the reply. Well, I tried like you said; in this
> case, I have an existing database with less than 150 Tables in it.
>
> For simplicity, I just picked one table called 'users' which was created
> with the following:
> CREATE TABLE users
> (
> dtype character
> varying(31) NOT NULL,
> id bigint NOT NULL,
> active boolean,
> autologin boolean
> NOT NULL,
> ...
> ... ...
> firstname
> character varying(255),
> lastname character
> varying(255),
> ...
> ... ...
> e_id bigint,
> CONSTRAINT
> users_pkey PRIMARY KEY (id),
> ...
> ... ...
> )
>
> On the other side, from the 8 ecore file's generated *.impl java
> packages, I picked one implementation class
> public class NaturalPersonImpl extends EObjectImpl implements
> NaturalPerson {
>
> I just planned to map the column 'firstname' in 'users' table with the
> 'firstName' attribute of the implementation class 'NaturalPersonImpl'
>
>
> Selecting all the 8 ecore files, I generated a *.hbm file which had a
> big pile of mappings in it. As mentioned above, for simplicity, I just
> picked the NaturalPersonimpl and its parent class from the
> generated-hbm.xml altered a bit which look like:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD
> 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
>
> <hibernate-mapping schema="public" auto-import="false">
>
> <class name="foundation.IdentifiableElement"
> entity-name="IdentifiableElement" abstract="true" lazy="false"
> discriminator-value="IdentifiableElement">
> <meta attribute="eclassName">IdentifiableElement</meta>
> <meta attribute="epackage">http://foundation/1.0</meta>
> <id type="long" name="e_id" column="e_id" access="
> org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie
> rPropertyHandler ">
> <meta attribute="syntheticId">true</meta>
> <generator class="native"/>
> </id>
> <discriminator type="string">
> <column name="dtype" index="identifiableelementdtype"
> length="255" not-null="true"/>
> </discriminator>
> <version name="e_version" column="e_version" access="
> org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
> <meta attribute="syntheticVersion">true</meta>
> </version>
> <property name="guid" lazy="false" insert="true" update="true"
> not-null="true" unique="false" type="java.lang.String">
> <column not-null="true" unique="false" name="`guid`"/>
> </property>
> <property name="namespace" lazy="false" insert="true"
> update="true" not-null="false" unique="false" type="java.lang.String">
> <column not-null="false" unique="false" name="`namespace`"/>
> </property>
> </class>
>
>
> <subclass name="foundation.impl.NaturalPersonImpl"
> entity-name="NaturalPerson" abstract="false" lazy="false"
> extends="IdentifiableElement" discriminator-value="NaturalPerson">
> <meta attribute="eclassName">NaturalPerson</meta>
> <meta attribute="epackage">http://foundation/1.0</meta>
> <join table="`users`">
> <key column="e_id"/>
> <property name="firstName" lazy="false" insert="true"
> update="true" not-null="false" unique="false" type="java.lang.String">
> <column not-null="false" unique="false" name="`firstname`"/>
> </property>
> </join>
> </subclass>
>
> </hibernate-mapping>
>
> With the .cfg.xml file configured, I ran the code:
>
> Transaction tx = null;
> Session session = SessionFactoryUtil.getInstance().openSession();
> Query query = session.createQuery("SELECT s FROM
> NaturalPerson s");
> List<NaturalPerson> natp1 = query.list();
> NaturalPerson natp2 = natp1.get(1);
> System.out.println(natp2.getFirstName());
>
> This threw me an error as follows:
>
> 03.03.2010 14:29:34 org.slf4j.impl.JCLLoggerAdapter info
> INFO: Hibernate Annotations 3.4.0.GA
> 03.03.2010 14:29:34 org.slf4j.impl.JCLLoggerAdapter info
> INFO: Hibernate 3.3.2.GA
> ... ... ... ...
> INFO: Configuration resource: /hibernate.cfg.xml
> 03.03.2010 14:29:34 org.slf4j.impl.JCLLoggerAdapter info
> INFO: Reading mappings from resource :
> com/sap/usdl3/queries/hibernate.hbm.xml
> ... ... ... ...
> INFO: using driver: org.postgresql.Driver at URL:
> jdbc:postgresql://localhost:5432/cdoago
> 03.03.2010 14:29:35 org.slf4j.impl.JCLLoggerAdapter info
> ... ... ... ...
> INFO: schema update complete
> Hibernate: select naturalper0_.e_id as e1_0_, naturalper0_.e_version as
> e3_0_, naturalper0_."guid" as guid4_0_, naturalper0_."namespace" as
> namespace5_0_, naturalper0_1_."firstname" as firstname2_1_ from
> public.IdentifiableElement naturalper0_ inner join public."users"
> naturalper0_1_ on naturalper0_.e_id=naturalper0_1_.e_id where
> naturalper0_.dtype='NaturalPerson'
> Exception in thread "main" java.lang.IndexOutOfBoundsException: Index:
> 1, Size: 0
> at java.util.ArrayList.RangeCheck(ArrayList.java:546)
> at java.util.ArrayList.get(ArrayList.java:321)
> at foundation.impl.CoreTesting.updateService(CoreTesting.java:4 1)
> at foundation.impl.CoreTesting.main(CoreTesting.java:31)
>
>
> Any idea would be helpful.


--

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+EMF] Meet-in-the-Middle mapping [message #518271 is a reply to message #518232] Wed, 03 March 2010 16:09 Go to previous messageGo to next message
Sudeep is currently offline SudeepFriend
Messages: 7
Registered: March 2010
Junior Member
Hello Martin,

a) Previous time, I did'nt use a Teneo data store. So, now I used the data store, with the same *cfg.xml and *.hbm.xml file for manual mapping.
But, this time
--> it is looking for 'hibernate.properties' file instead of *.cfg.xml file
03.03.2010 16:51:50 org.slf4j.impl.JCLLoggerAdapter info
INFO: hibernate.properties not found

--> eventually without the use of *.hbm.xml file, it is automatically mapping.
03.03.2010 16:51:50 org.eclipse.emf.teneo.classloader.ClassLoaderResolver setClassLoaderStrategy
INFO: Class loader strategy set to: org.eclipse.emf.teneo.classloader.ContextClassLoaderStrategy
03.03.2010 16:51:50 org.slf4j.impl.JCLLoggerAdapter info
INFO: Mapping class: NamedElement -> namedelement
03.03.2010 16:51:50 org.slf4j.impl.JCLLoggerAdapter info
INFO: Mapping collection: NamedElement.synonyms -> namedelement_synonyms
... ... ... ..

and gave me an exception for the non-availability of hibernate.properties file:

Exception in thread "main" org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection avalable
at org.hibernate.dialect.resolver.DialectFactory.buildDialect(D ialectFactory.java:107)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFact ory.java:138)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Config uration.java:2119)
at org.hibernate.cfg.Configuration.buildSettings(Configuration. java:2115)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configur ation.java:1339)
at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.buildSess ionFactory(HbSessionDataStore.java:205)
at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.initializ e(HbSessionDataStore.java:90)


b) Next, I included the 'hibernate.properties file'

INFO: Hibernate 3.3.2.GA
03.03.2010 16:59:54 org.slf4j.impl.JCLLoggerAdapter info
INFO: loaded properties from resource hibernate.properties: {hibernate.connection.username=cdo_user, hibernate.connection.password=****, hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect, hibernate.connection.url=jdbc:postgresql://localhost/test, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.driver_class=org.postgresql.Driver, hibernate.hbm2ddl.auto=true}

like I specified in *.cfg.xml file, there is no choice(or I'm missing it?!) for putting 'mapping resource' in hibernate.properties file, Teneo again maps
automatically like before and this time I received an Exception as follows:

03.03.2010 16:59:57 org.slf4j.impl.JCLLoggerAdapter info
INFO: indexes: [yearrange_weekranges_pkey]
03.03.2010 16:59:57 org.slf4j.impl.JCLLoggerAdapter info
INFO: schema update complete
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:546)
at java.util.ArrayList.get(ArrayList.java:321)
at foundation.impl.CoreTesting.updateService(CoreTesting.java:5 7)
at foundation.impl.CoreTesting.main(CoreTesting.java:40)

Code reference:
===============

SessionFactory fsession = foundationds.getSessionFactory();
Session session = fsession.openSession();
session.beginTransaction();

Query query = session.createQuery("SELECT s FROM NaturalPerson s");
List<NaturalPerson> natp1 = query.list();
NaturalPerson natp2 = natp1.get(1);
System.out.println(natp2.getFirstName());

Dependencies:
=============
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.emf.ecore;visibility:=reexport,
org.eclipse.emf.ecore.xmi;visibility:=reexport,
com.springsource.antlr;bundle-version="2.7.7",
com.springsource.javax.transaction;bundle-version="1.1.0",
com.springsource.org.apache.commons.collections;bundle-versi on= "3.2.0",
com.springsource.org.apache.commons.logging;bundle-version="1.1.1 ",
com.springsource.org.dom4j;bundle-version="1.6.1",
com.springsource.org.hibernate;bundle-version="3.3.2",
com.springsource.org.postgresql.jdbc3;bundle-version="8.3.603 ",
javax.activation;bundle-version="1.1.0",
javax.xml.stream;bundle-version="1.0.1",
org.eclipse.emf.teneo.hibernate;bundle-version="1.1.1",
slf4j.api;bundle-version="1.5.8",
javax.persistence;bundle-version="1.99.0",
org.apache.lucene;bundle-version="1.9.1"


cheers,
Sudeep
Re: [Teneo+EMF] Meet-in-the-Middle mapping [message #518279 is a reply to message #518271] Wed, 03 March 2010 16:24 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Sudeep,
The mapping file is passed in as a property to Teneo, this should be done programmatically currently. You can write your
own property-reader to read properties from a file to pass them into Teneo.

To detect if it is a problem in Teneo/Hibernate with the mapping or the data. Can you execute this query directly in a
database explorer (in the database):
select naturalper0_.e_id as e1_0_, naturalper0_.e_version as e3_0_, naturalper0_."guid" as guid4_0_,
naturalper0_."namespace" as namespace5_0_, naturalper0_1_."firstname" as firstname2_1_ from public.IdentifiableElement
naturalper0_ inner join public."users" naturalper0_1_ on naturalper0_.e_id=naturalper0_1_.e_id where
naturalper0_.dtype='NaturalPerson'

does this this return anything? If not then you need to check why it doesn't, my guess is that it has to do with the
inner join or the dtype clause.

gr. Martin

Sudeep wrote:
> Hello Martin,
>
> a) Previous time, I did'nt use a Teneo data store. So, now I used the
> data store, with the same *cfg.xml and *.hbm.xml file for manual
> mapping. But, this time
> --> it is looking for 'hibernate.properties' file instead of
> *.cfg.xml file
> 03.03.2010 16:51:50 org.slf4j.impl.JCLLoggerAdapter info
> INFO: hibernate.properties not found
>
> --> eventually without the use of *.hbm.xml file, it is
> automatically mapping.
> 03.03.2010 16:51:50
> org.eclipse.emf.teneo.classloader.ClassLoaderResolver
> setClassLoaderStrategy
> INFO: Class loader strategy set to:
> org.eclipse.emf.teneo.classloader.ContextClassLoaderStrategy
> 03.03.2010 16:51:50 org.slf4j.impl.JCLLoggerAdapter info
> INFO: Mapping class: NamedElement -> namedelement
> 03.03.2010 16:51:50 org.slf4j.impl.JCLLoggerAdapter info
> INFO: Mapping collection: NamedElement.synonyms ->
> namedelement_synonyms
> ... ... ... ..
>
> and gave me an exception for the non-availability of
> hibernate.properties file:
>
> Exception in thread "main" org.hibernate.HibernateException:
> 'hibernate.dialect' must be set when no Connection avalable
> at org.hibernate.dialect.resolver.DialectFactory.buildDialect(D
> ialectFactory.java:107)
> at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFact
> ory.java:138)
> at org.hibernate.cfg.Configuration.buildSettingsInternal(Config
> uration.java:2119)
> at org.hibernate.cfg.Configuration.buildSettings(Configuration.
> java:2115)
> at org.hibernate.cfg.Configuration.buildSessionFactory(Configur
> ation.java:1339)
> at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.buildSess
> ionFactory(HbSessionDataStore.java:205)
> at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.initializ
> e(HbSessionDataStore.java:90)
>
>
> b) Next, I included the 'hibernate.properties file'
> INFO: Hibernate 3.3.2.GA
> 03.03.2010 16:59:54 org.slf4j.impl.JCLLoggerAdapter info
> INFO: loaded properties from resource hibernate.properties:
> {hibernate.connection.username=cdo_user,
> hibernate.connection.password=****,
> hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect,
> hibernate.connection.url=jdbc:postgresql://localhost/test,
> hibernate.bytecode.use_reflection_optimizer=false,
> hibernate.connection.driver_class=org.postgresql.Driver,
> hibernate.hbm2ddl.auto=true}
>
> like I specified in *.cfg.xml file, there is no choice(or I'm missing
> it?!) for putting 'mapping resource' in hibernate.properties file, Teneo
> again maps
> automatically like before and this time I received an Exception as follows:
>
> 03.03.2010 16:59:57 org.slf4j.impl.JCLLoggerAdapter info
> INFO: indexes: [yearrange_weekranges_pkey]
> 03.03.2010 16:59:57 org.slf4j.impl.JCLLoggerAdapter info
> INFO: schema update complete
> Exception in thread "main" java.lang.IndexOutOfBoundsException: Index:
> 1, Size: 0
> at java.util.ArrayList.RangeCheck(ArrayList.java:546)
> at java.util.ArrayList.get(ArrayList.java:321)
> at foundation.impl.CoreTesting.updateService(CoreTesting.java:5 7)
> at foundation.impl.CoreTesting.main(CoreTesting.java:40)
>
> Code reference:
> ===============
>
> SessionFactory fsession = foundationds.getSessionFactory();
> Session session = fsession.openSession();
> session.beginTransaction();
>
> Query query = session.createQuery("SELECT s FROM NaturalPerson s");
> List<NaturalPerson> natp1 = query.list();
> NaturalPerson natp2 = natp1.get(1);
> System.out.println(natp2.getFirstName());
>
> Dependencies:
> =============
> Require-Bundle: org.eclipse.core.runtime,
> org.eclipse.emf.ecore;visibility:=reexport,
> org.eclipse.emf.ecore.xmi;visibility:=reexport,
> com.springsource.antlr;bundle-version="2.7.7",
> com.springsource.javax.transaction;bundle-version="1.1.0",
> com.springsource.org.apache.commons.collections;bundle-versi on= "3.2.0",
> com.springsource.org.apache.commons.logging;bundle-version="1.1.1 ",
> com.springsource.org.dom4j;bundle-version="1.6.1",
> com.springsource.org.hibernate;bundle-version="3.3.2",
> com.springsource.org.postgresql.jdbc3;bundle-version="8.3.603 ",
> javax.activation;bundle-version="1.1.0",
> javax.xml.stream;bundle-version="1.0.1",
> org.eclipse.emf.teneo.hibernate;bundle-version="1.1.1",
> slf4j.api;bundle-version="1.5.8",
> javax.persistence;bundle-version="1.99.0",
> org.apache.lucene;bundle-version="1.9.1"
>


--

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+EMF] Meet-in-the-Middle mapping [message #518284 is a reply to message #518279] Wed, 03 March 2010 16:44 Go to previous messageGo to next message
Sudeep is currently offline SudeepFriend
Messages: 7
Registered: March 2010
Junior Member
I get this(shown below) when I query directly the database:

cdoago=# select naturalper0_.e_id as e1_0_, naturalper0_.e_version as e3_0_, nat
uralper0_."guid" as guid4_0_, naturalper0_."namespace" as namespace5_0_, natural
per0_1_."firstname" as firstname2_1_ from public.IdentifiableElement naturalper0
_ inner join public."users" naturalper0_1_ on naturalper0_.e_id=naturalper0_1_.e
_id where naturalper0_.dtype='NaturalPerson';
e1_0_ | e3_0_ | guid4_0_ | namespace5_0_ | firstname2_1_
-------+-------+----------+---------------+---------------
(0 Zeilen)

cdoago=#
cdoago=#


cheers,
Sudeep
Re: [Teneo+EMF] Meet-in-the-Middle mapping [message #518295 is a reply to message #518284] Wed, 03 March 2010 17:12 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
0 Zeilen means no results I guess.

This is the reason that the collection has a zero size.

Can you investigate why no results are returned?

gr. Martin

Sudeep wrote:
> I get this(shown below) when I query directly the database:
>
> cdoago=# select naturalper0_.e_id as e1_0_, naturalper0_.e_version as
> e3_0_, nat
> uralper0_."guid" as guid4_0_, naturalper0_."namespace" as namespace5_0_,
> natural
> per0_1_."firstname" as firstname2_1_ from public.IdentifiableElement
> naturalper0
> _ inner join public."users" naturalper0_1_ on
> naturalper0_.e_id=naturalper0_1_.e
> _id where naturalper0_.dtype='NaturalPerson';
> e1_0_ | e3_0_ | guid4_0_ | namespace5_0_ | firstname2_1_
> -------+-------+----------+---------------+---------------
> (0 Zeilen)
>
> cdoago=#
> cdoago=#


--

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+EMF] Meet-in-the-Middle mapping [message #518477 is a reply to message #518295] Thu, 04 March 2010 09:21 Go to previous messageGo to next message
Sudeep is currently offline SudeepFriend
Messages: 7
Registered: March 2010
Junior Member
yes Martin, 0 Zeilen=0 Rows.

Well, I thought that a jdbc connection will be established between the EClass 'NaturalPerson' and the Table 'users', so all the data in 'users' table will be made available at the EClass 'NaturalPerson' too.

If I'm right with the preceding sentence, having now 0 results, I guess there is no mapping established between the EClass and table.

I must figure out where I'm making mistake and will update you soon.


cheers,
Sudeep
Re: [Teneo+EMF] Meet-in-the-Middle mapping [message #518485 is a reply to message #518477] Thu, 04 March 2010 04:44 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Sudeep,
There is a mapping between the Eclass and the table. The question is only if the resulting query is what you want.

This is the query generated by hibernate:
select naturalper0_.e_id as e1_0_, naturalper0_.e_version as e3_0_, naturalper0_."guid" as guid4_0_,
naturalper0_."namespace" as namespace5_0_, naturalper0_1_."firstname" as firstname2_1_ from public.IdentifiableElement
naturalper0_ inner join public."users" naturalper0_1_ on naturalper0_.e_id=naturalper0_1_.e_id where
naturalper0_.dtype='NaturalPerson'

The problem that nothing is returned can be one of:
1) the where clause: naturalper0_.dtype='NaturalPerson', does the dtype column indeed contain a NaturalPerson value?
2) inner join public."users" naturalper0_1_ on naturalper0_.e_id=naturalper0_1_.e_id
are there records in IdentifiableElement and users which have an e_id with the same value?

if 1) is the problem then the dtype name can be changed using a @DiscriminatorValue annotation.
if 2) is the problem then you need to check how the join between the two tables should be done (which columns should be
used) and change the mapping accordingly.

gr. Martin


Sudeep wrote:
> yes Martin, 0 Zeilen=0 Rows.
>
> Well, I thought that a jdbc connection will be established between the
> EClass 'NaturalPerson' and the Table 'users', so all the data in 'users'
> table will be made available at the EClass 'NaturalPerson' too.
> If I'm right with the preceding sentence, having now 0 results, I guess
> there is no mapping established between the EClass and table.
> I must figure out where I'm making mistake and will update you soon.


--

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+EMF] Meet-in-the-Middle mapping [message #518494 is a reply to message #518485] Thu, 04 March 2010 10:02 Go to previous messageGo to next message
Sudeep is currently offline SudeepFriend
Messages: 7
Registered: March 2010
Junior Member
Oh! Thanks for that good tip. I'll figure it out now and will update my reply soon.

cheers,
Sudeep
Re: [Teneo+EMF] Meet-in-the-Middle mapping [message #521366 is a reply to message #518494] Wed, 17 March 2010 12:37 Go to previous messageGo to next message
Sudeep is currently offline SudeepFriend
Messages: 7
Registered: March 2010
Junior Member
Hello Martin,
Sorry for the delayed reply. It took some time to try out other Hibernate Inheritance mapping strategies.

With the JOINED inheritance strategy, in my case, the Identifier Generator (by default: generator class: native, I tried others too, but sadly no change)did'nt generate Primary Key/e_id for the superclass table and so consequently, there were no Foreign Key generated in the subclass table, hence it didnt allow persistence, returning null values.

I did'nt wanted SINGLE_TABLE strategy because, in my case I need separate tables for the subclasses.

In the end, I tried with the TABLE_PER_CLASS strategy and it worked! It generated the identifier in the existing subclass table from the next free row and persisted.

Thanks Martin, once again for the useful tips.

Also, I would like to know if you have published some papers(like articles, proceedings in conference) regarding 'Model-Relational Mapping' or Teneo, so that I can get better theoretical knowledge too.


cheers,
Sudeep
Re: [Teneo+EMF] Meet-in-the-Middle mapping [message #521379 is a reply to message #521366] Wed, 17 March 2010 13:09 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Sudeep,
Good that it works!

I think that the best place for information is the Teneo wiki which is quite extensive:
http://wiki.eclipse.org/Teneo/Hibernate
with this specific part on model relational mapping:
http://wiki.eclipse.org/Teneo/Hibernate/ModelRelational

gr. Martin

Sudeep wrote:
> Hello Martin,
> Sorry for the delayed reply. It took some time to try
> out other Hibernate Inheritance mapping strategies.
>
> With the JOINED inheritance strategy, in my case, the Identifier
> Generator (by default: generator class: native, I tried others too, but
> sadly no change)did'nt generate Primary Key/e_id for the superclass
> table and so consequently, there were no Foreign Key generated in the
> subclass table, hence it didnt allow persistence, returning null values.
>
> I did'nt wanted SINGLE_TABLE strategy because, in my case I need
> separate tables for the subclasses.
>
> In the end, I tried with the TABLE_PER_CLASS strategy and it worked! It
> generated the identifier in the existing subclass table from the next
> free row and persisted.
>
> Thanks Martin, once again for the useful tips.
>
> Also, I would like to know if you have published some papers(like
> articles, proceedings in conference) regarding 'Model-Relational
> Mapping' or Teneo, so that I can get better theoretical knowledge too.


--

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
Previous Topic:XMI and mixed content
Next Topic:Handle special character in uri
Goto Forum:
  


Current Time: Fri Apr 26 22:32:23 GMT 2024

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

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

Back to the top