Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Teneo + EcoreUtil.Copier: Wrong ID ..?
Teneo + EcoreUtil.Copier: Wrong ID ..? [message #543935] Thu, 01 July 2010 07:22 Go to next message
Wolf Fischer is currently offline Wolf FischerFriend
Messages: 43
Registered: July 2009
Member
Hi there,

i am currently trying to import an existing model file into our database. The model file can be loaded without problems into the editor.
So what i am doing is to load the file as a resource and the database as another one. Then i use the copier to copy the complete file resource set:
Copier copier = new Copier();
		Collection<EObject> allelements = copier.copyAll(res_file.getContents());
		copier.copyReferences();


And finally i add it to the database resource and save it all:

res_db.getContents().addAll(allelements);
SessionFactory sf = hbs.getSessionFactory();
Session s = sf.openSession();
s.beginTransaction();
res_db.save(Collections.EMPTY_MAP);
s.getTransaction().commit();


The process runs through just fine by now, no exceptions being thrown. However if i try to open the database in my editor, i get the following exception:

org.hibernate.WrongClassException: Object with id: 8 was not of the specified subclass: SyntacticElement (loaded object was of wrong class class de.uniaugsburg.brms.model.impl.SemanticElementImpl)

So seemingly the Copier somehow managed to "transform" some of my class(es?) into a new type..? Or whats the problem here? Can someone help me on this one?

Thanks in advance!

Wolf
Re: Teneo + EcoreUtil.Copier: Wrong ID ..? [message #543968 is a reply to message #543935] Thu, 01 July 2010 08:41 Go to previous messageGo to next message
Wolf Fischer is currently offline Wolf FischerFriend
Messages: 43
Registered: July 2009
Member
I just tried several things: One was the use of the EcoreUtil.copyall Method (which yielded the same results), the other was taking the objects directly from the file resource and adding it to the db-resource without copying them. To my surprise, this way the elements still were being inserted into the DB and the original error remained, when opening the DB with the editor...
So - why does hibernate have a problem with a structure that seems to be perfectly legitimate to the editor, if coming directly from the file?
Re: Teneo + EcoreUtil.Copier: Wrong ID ..? [message #544005 is a reply to message #543968] Thu, 01 July 2010 10:00 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Wolf,
Depending on the inheritance mapping strategy Hibernate stores objects of different types in one table. Then when
retrieving references (many-to-one) it checks that the retrieved object is indeed of the expected type. In your case
there is something wrong there.

Another reason can be that there are name clashes in ereferences names in different subclasses which are stored in the
same table and therefore are stored in the same column. Resulting in illegal references. Can this be the case in your
model that there are 2 subtypes which have ereferences with the same name?

Can you try with the option:
teneo.mapping.inheritance
set to the value:
JOINED

gr. Martin


On 07/01/2010 10:41 AM, Wolf Fischer wrote:
> I just tried several things: One was the use of the EcoreUtil.copyall
> Method (which yielded the same results), the other was taking the
> objects directly from the file resource and adding it to the db-resource
> without copying them. To my surprise, this way the elements still were
> being inserted into the DB and the original error remained, when opening
> the DB with the editor... So - why does hibernate have a problem with a
> structure that seems to be perfectly legitimate to the editor, if coming
> directly from the file?


--

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 + EcoreUtil.Copier: Wrong ID ..? [message #544015 is a reply to message #543935] Thu, 01 July 2010 11:14 Go to previous messageGo to next message
Wolf Fischer is currently offline Wolf FischerFriend
Messages: 43
Registered: July 2009
Member
Hi Martin,

Thanks for your answer!
My standard mapping.inheritance was set to single. If i switch to "JOINED", i get the following exception:
0 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Field 'dtype' doesn't have a default value
org.hibernate.exception.GenericJDBCException: could not insert: [Domain]
at org.hibernate.exception.SQLStateConverter.handledNonSpecific Exception(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateCo nverter.java:114)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExce ptionHelper.java:66)
at org.hibernate.id.insert.AbstractReturningDelegate.performIns ert(AbstractReturningDelegate.java:64)
at org.hibernate.persister.entity.AbstractEntityPersister.inser t(AbstractEntityPersister.java:2176)
at org.hibernate.persister.entity.AbstractEntityPersister.inser t(AbstractEntityPersister.java:2656)
at org.hibernate.action.EntityIdentityInsertAction.execute(Enti tyIdentityInsertAction.java:71)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:27 9)
at org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:321)
at org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:130)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:210)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.per formSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl. java:535)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java :527)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java :523)
at org.eclipse.emf.teneo.hibernate.HbSessionWrapper.saveOrUpdat e(HbSessionWrapper.java:161)
at org.eclipse.emf.teneo.hibernate.resource.HibernateResource.s aveResource(HibernateResource.java:351)
at org.eclipse.emf.teneo.resource.StoreResource.save(StoreResou rce.java:405)
at brms.helper.ImportFile2DB.convert(ImportFile2DB.java:125)
at brms.helper.ImportFile2DB.main(ImportFile2DB.java:179)
Caused by: java.sql.SQLException: Field 'dtype' doesn't have a default value
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:107 2)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3563)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3495)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:26 93)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedSta tement.java:2102)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedState ment.java:2395)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedState ment.java:2313)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedState ment.java:2298)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate. executeAndExtract(IdentityGenerator.java:94)
at org.hibernate.id.insert.AbstractReturningDelegate.performIns ert(AbstractReturningDelegate.java:57)
... 19 more


As for the same name in different subclasses: The SyntacticElement and the SemanticElement both inherit from the same class. Both elements have an attribute with the same name, but of different types. Is there some way of resolving this issue with the SINGLE_TABLE inheritance mapping?

Regards,

Wolf
Re: Teneo + EcoreUtil.Copier: Wrong ID ..? [message #544171 is a reply to message #544015] Thu, 01 July 2010 21:30 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Wolf,
With single table inheritance, can you set a @JoinColumn(name='myuniquename') on one of the two ereferences to give it
another unique name.

gr. Martin

On 07/01/2010 01:14 PM, Wolf Fischer wrote:
> Hi Martin,
>
> Thanks for your answer!
> My standard mapping.inheritance was set to single. If i switch to
> "JOINED", i get the following exception:
> 0 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Field 'dtype'
> doesn't have a default value
> org.hibernate.exception.GenericJDBCException: could not insert: [Domain]
> at org.hibernate.exception.SQLStateConverter.handledNonSpecific
> Exception(SQLStateConverter.java:126)
> at org.hibernate.exception.SQLStateConverter.convert(SQLStateCo
> nverter.java:114)
> at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExce
> ptionHelper.java:66)
> at org.hibernate.id.insert.AbstractReturningDelegate.performIns
> ert(AbstractReturningDelegate.java:64)
> at org.hibernate.persister.entity.AbstractEntityPersister.inser
> t(AbstractEntityPersister.java:2176)
> at org.hibernate.persister.entity.AbstractEntityPersister.inser
> t(AbstractEntityPersister.java:2656)
> at org.hibernate.action.EntityIdentityInsertAction.execute(Enti
> tyIdentityInsertAction.java:71)
> at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:27 9)
> at org.hibernate.event.def.AbstractSaveEventListener.performSav
> eOrReplicate(AbstractSaveEventListener.java:321)
> at org.hibernate.event.def.AbstractSaveEventListener.performSav
> e(AbstractSaveEventListener.java:204)
> at org.hibernate.event.def.AbstractSaveEventListener.saveWithGe
> neratedId(AbstractSaveEventListener.java:130)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav
> eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:210)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent
> ityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.per
> formSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS
> aveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
> at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl. java:535)
> at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java :527)
> at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java :523)
> at org.eclipse.emf.teneo.hibernate.HbSessionWrapper.saveOrUpdat
> e(HbSessionWrapper.java:161)
> at org.eclipse.emf.teneo.hibernate.resource.HibernateResource.s
> aveResource(HibernateResource.java:351)
> at org.eclipse.emf.teneo.resource.StoreResource.save(StoreResou
> rce.java:405)
> at brms.helper.ImportFile2DB.convert(ImportFile2DB.java:125)
> at brms.helper.ImportFile2DB.main(ImportFile2DB.java:179)
> Caused by: java.sql.SQLException: Field 'dtype' doesn't have a default
> value
> at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:107 2)
> at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3563)
> at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3495)
> at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
> at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
> at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:26 93)
> at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedSta
> tement.java:2102)
> at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedState
> ment.java:2395)
> at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedState
> ment.java:2313)
> at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedState
> ment.java:2298)
> at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.
> executeAndExtract(IdentityGenerator.java:94)
> at org.hibernate.id.insert.AbstractReturningDelegate.performIns
> ert(AbstractReturningDelegate.java:57)
> ... 19 more
>
>
> As for the same name in different subclasses: The SyntacticElement and
> the SemanticElement both inherit from the same class. Both elements have
> an attribute with the same name, but of different types. Is there some
> way of resolving this issue with the SINGLE_TABLE inheritance mapping?
>
> Regards,
>
> Wolf


--

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 + EcoreUtil.Copier: Wrong ID ..? [message #544199 is a reply to message #543935] Fri, 02 July 2010 00:16 Go to previous messageGo to next message
Wolf Fischer is currently offline Wolf FischerFriend
Messages: 43
Registered: July 2009
Member
Hello Martin,

how / where do I set the @JoinColumn flag?

Regards,

Wolf
Re: Teneo + EcoreUtil.Copier: Wrong ID ..? [message #544240 is a reply to message #544199] Fri, 02 July 2010 06:32 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Wolf,
See here:
http://wiki.eclipse.org/Teneo/Hibernate/ModelRelational/Anno tations_Format

gr. Martin

On 07/02/2010 02:16 AM, Wolf Fischer wrote:
> Hello Martin,
>
> how / where do I set the @JoinColumn flag?
>
> Regards,
>
> Wolf


--

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 + EcoreUtil.Copier: Wrong ID ..? [message #544376 is a reply to message #543935] Fri, 02 July 2010 13:44 Go to previous messageGo to next message
Wolf Fischer is currently offline Wolf FischerFriend
Messages: 43
Registered: July 2009
Member
Hi Martin,

Thanks again! It works now! Just one more question:
I followed the examples and instructions from the link (at least I think I did Wink). I added the annotations from within the Ecore-Editor, so that the file looks like the following:
<eClassifiers xsi:type="ecore:EClass" name="SyntacticElement" eSuperTypes="#//Element">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="value" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="belongsToSyntacticScope"
        upperBound="-1" eType="#//SyntacticScope" eOpposite="#//SyntacticScope/consistsOfElements"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="referencedBySymbol" upperBound="-1"
        eType="#//SyntacticSymbol" eOpposite="#//SyntacticSymbol/referencesElement">
      <eAnnotations source="teneo.jpa">
        <details key="appinfo" value="@JoinColumn(name=&quot;referencedBySynSymbol&quot;)"/>
      </eAnnotations>
    </eStructuralFeatures>
  </eClassifiers>


However if I look at the DB there is no column / table, named "referencedBySynSymbol" (I refreshed my DB several times). How is Teneo handling the internal mapping?

Regards,

Wolf
Re: Teneo + EcoreUtil.Copier: Wrong ID ..? [message #544405 is a reply to message #544376] Fri, 02 July 2010 14:55 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Wolf,
If it works now it must have had some effect :-). The subtypes are all stored in the table of the root class/type, can
you check that table?

gr. Martin

On 07/02/2010 03:44 PM, Wolf Fischer wrote:
> Hi Martin,
>
> Thanks again! It works now! Just one more question:
> I followed the examples and instructions from the link (at least I think
> I did ;)). I added the annotations from within the Ecore-Editor, so that
> the file looks like the following:
>
> <eClassifiers xsi:type="ecore:EClass" name="SyntacticElement"
> eSuperTypes="#//Element">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="value"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EReference"
> name="belongsToSyntacticScope"
> upperBound="-1" eType="#//SyntacticScope"
> eOpposite="#//SyntacticScope/consistsOfElements"/>
> <eStructuralFeatures xsi:type="ecore:EReference"
> name="referencedBySymbol" upperBound="-1"
> eType="#//SyntacticSymbol"
> eOpposite="#//SyntacticSymbol/referencesElement">
> <eAnnotations source="teneo.jpa">
> <details key="appinfo" value="@JoinColumn(name="referencedBySynSymbol")"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
>
>
> However if I look at the DB there is no column / table, named
> "referencedBySynSymbol" (I refreshed my DB several times). How is Teneo
> handling the internal mapping?
>
> Regards,
>
> Wolf


--

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:How to read an Ecore model
Next Topic:Using CDO with an Xtext model
Goto Forum:
  


Current Time: Sat Sep 21 02:11:12 GMT 2024

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

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

Back to the top