Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO/Hibernate/Teneo] java.lang.String cannot be cast to java.lang.Long
[CDO/Hibernate/Teneo] java.lang.String cannot be cast to java.lang.Long [message #871512] Mon, 14 May 2012 09:58 Go to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
I have a case where a String is provided whereas a Long is expected:

java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long
	at org.hibernate.type.descriptor.java.LongTypeDescriptor.unwrap(LongTypeDescriptor.java:36)
	at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$1.doBind(BigIntTypeDescriptor.java:52)
	at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:89)
	at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:282)
	at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:277)
	at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:85)
	at org.hibernate.type.AnyType.nullSafeSet(AnyType.java:162)
	at org.hibernate.persister.collection.AbstractCollectionPersister.writeElement(AbstractCollectionPersister.java:815)
	at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1203)
	at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:58)
	at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:188)
	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
	at org.eclipse.emf.cdo.server.internal.hibernate.HibernateStoreAccessor.doWrite(HibernateStoreAccessor.java:689)
	at org.eclipse.emf.cdo.spi.server.StoreAccessorBase.write(StoreAccessorBase.java:149)
	at org.eclipse.emf.cdo.internal.server.TransactionCommitContext.write(TransactionCommitContext.java:487)
	at org.eclipse.emf.cdo.spi.server.InternalCommitContext$1.runLoop(InternalCommitContext.java:43)
	at org.eclipse.emf.cdo.spi.server.InternalCommitContext$1.runLoop(InternalCommitContext.java:1)
	at org.eclipse.net4j.util.om.monitor.ProgressDistributor.run(ProgressDistributor.java:96)
	at org.eclipse.emf.cdo.server.internal.net4j.protocol.CommitTransactionIndication.indicatingCommit(CommitTransactionIndication.java:262)
	at org.eclipse.emf.cdo.server.internal.net4j.protocol.CommitTransactionIndication.indicating(CommitTransactionIndication.java:96)
	at org.eclipse.emf.cdo.server.internal.net4j.protocol.CDOServerIndicationWithMonitoring.indicating(CDOServerIndicationWithMonitoring.java:109)
	at org.eclipse.net4j.signal.IndicationWithMonitoring.indicating(IndicationWithMonitoring.java:84)
	at org.eclipse.net4j.signal.IndicationWithResponse.doExtendedInput(IndicationWithResponse.java:90)
	at org.eclipse.net4j.signal.Signal.doInput(Signal.java:326)
	at org.eclipse.net4j.signal.IndicationWithResponse.execute(IndicationWithResponse.java:63)
	at org.eclipse.net4j.signal.IndicationWithMonitoring.execute(IndicationWithMonitoring.java:63)
	at org.eclipse.net4j.signal.Signal.runSync(Signal.java:251)
	at org.eclipse.net4j.signal.Signal.run(Signal.java:147)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)


Hints:
- org.hibernate.type.descriptor.sql.new BasicBinder() {...}.doBind(PreparedStatement, X, int, WrapperOptions)
-> value of X is a String (UUID)
- JavaTypeDescriptor is instanceof LongTypeDescriptor which leads to the ClassCastException when the String UUID is provided to org.hibernate.type.descriptor.java.JavaTypeDescriptor.unwrap(Long, Class<Long>, WrapperOptions)

The insert statement which is being executed:

Hibernate: insert into [pictogramlink_businessobjects] ([pictogramlink_e_id], [businessobjects_type], [businessobjects_id]) values (?, ?, ?)


Notes:
This is the linkage insert, i.e. a Graphiti Pictogram Element (legacy mode, pictogramlink_e_id) is linked to a business object from our own meta-model...
Maybe, some sort of CDOID types mismatch?
Re: [CDO/Hibernate/Teneo] java.lang.String cannot be cast to java.lang.Long [message #871543 is a reply to message #871512] Mon, 14 May 2012 11:22 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Erdal,
Afaics this is a so-called anytype ereference, so the model does not explicitly define the type, it is EObject. To model
this correctly with strings you would need to add this annotation to the graphitic ecore:

@AnyMetaDef(idType =
"string",metaType = "string")
but then all your types stored in this ereference should have a string idtype.

Note that if you don't control the graphiti model then you can also use xml to define annotations:
http://wiki.eclipse.org/Teneo/Hibernate/ModelRelational/Annotations_Format#JPA_Annotations_in_XML

Or you can use an external reference, so map this ereference as an external link instead of as an anytype:
http://wiki.eclipse.org/Teneo/Hibernate/ModelRelational/Association_Mapping#Storing_external_references_.28to_non-persisted_objects.29.2C_customizing_persisting_references

gr. Martin

On 05/14/2012 11:58 AM, Erdal Karaca wrote:
> I have a case where a String is provided whereas a Long is expected:
>
>
> java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long
> at org.hibernate.type.descriptor.java.LongTypeDescriptor.unwrap(LongTypeDescriptor.java:36)
> at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$1.doBind(BigIntTypeDescriptor.java:52)
> at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:89)
> at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:282)
> at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:277)
> at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:85)
> at org.hibernate.type.AnyType.nullSafeSet(AnyType.java:162)
> at org.hibernate.persister.collection.AbstractCollectionPersister.writeElement(AbstractCollectionPersister.java:815)
> at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1203)
> at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:58)
> at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
> at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
> at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:188)
> at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
> at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
> at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
> at org.eclipse.emf.cdo.server.internal.hibernate.HibernateStoreAccessor.doWrite(HibernateStoreAccessor.java:689)
> at org.eclipse.emf.cdo.spi.server.StoreAccessorBase.write(StoreAccessorBase.java:149)
> at org.eclipse.emf.cdo.internal.server.TransactionCommitContext.write(TransactionCommitContext.java:487)
> at org.eclipse.emf.cdo.spi.server.InternalCommitContext$1.runLoop(InternalCommitContext.java:43)
> at org.eclipse.emf.cdo.spi.server.InternalCommitContext$1.runLoop(InternalCommitContext.java:1)
> at org.eclipse.net4j.util.om.monitor.ProgressDistributor.run(ProgressDistributor.java:96)
> at
> org.eclipse.emf.cdo.server.internal.net4j.protocol.CommitTransactionIndication.indicatingCommit(CommitTransactionIndication.java:262)
>
> at
> org.eclipse.emf.cdo.server.internal.net4j.protocol.CommitTransactionIndication.indicating(CommitTransactionIndication.java:96)
>
> at
> org.eclipse.emf.cdo.server.internal.net4j.protocol.CDOServerIndicationWithMonitoring.indicating(CDOServerIndicationWithMonitoring.java:109)
>
> at org.eclipse.net4j.signal.IndicationWithMonitoring.indicating(IndicationWithMonitoring.java:84)
> at org.eclipse.net4j.signal.IndicationWithResponse.doExtendedInput(IndicationWithResponse.java:90)
> at org.eclipse.net4j.signal.Signal.doInput(Signal.java:326)
> at org.eclipse.net4j.signal.IndicationWithResponse.execute(IndicationWithResponse.java:63)
> at org.eclipse.net4j.signal.IndicationWithMonitoring.execute(IndicationWithMonitoring.java:63)
> at org.eclipse.net4j.signal.Signal.runSync(Signal.java:251)
> at org.eclipse.net4j.signal.Signal.run(Signal.java:147)
> at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
> at java.lang.Thread.run(Unknown Source)
>
>
> Hints:
> - org.hibernate.type.descriptor.sql.new BasicBinder() {...}.doBind(PreparedStatement, X, int, WrapperOptions)
> -> value of X is a String (UUID)
> - JavaTypeDescriptor is instanceof LongTypeDescriptor which leads to the ClassCastException when the String UUID is
> provided to org.hibernate.type.descriptor.java.JavaTypeDescriptor.unwrap(Long, Class<Long>, WrapperOptions)
>
> The insert statement which is being executed:
>
>
> Hibernate: insert into [pictogramlink_businessobjects] ([pictogramlink_e_id], [businessobjects_type],
> [businessobjects_id]) values (?, ?, ?)
>
>
> Notes:
> This is the linkage insert, i.e. a Graphiti Pictogram Element (legacy mode, pictogramlink_e_id) is linked to a business
> object from our own meta-model...
> Maybe, some sort of CDOID types mismatch?


--

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: [CDO/Hibernate/Teneo] java.lang.String cannot be cast to java.lang.Long [message #871561 is a reply to message #871543] Mon, 14 May 2012 12:24 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
Yes, I dont own the graphiti ecore, or I dont want to touch it...

I remember to avoid FeatureMaps and external refs in CDO...

So, I have to try to extend the mapping using the xml file.

I have downloaded the xsd, but not sure how to define the xml exactly.

<persistence-mapping>
	<epackage namespace-uri="http://eclipse.org/graphiti/mm">
	</epackage>
	<epackage namespace-uri="http://eclipse.org/graphiti/mm/pictograms">
	</epackage>
	<epackage namespace-uri="http://eclipse.org/graphiti/mm/algorithms">
	</epackage>
	<epackage namespace-uri="http://eclipse.org/graphiti/mm/algorithms/styles">
	</epackage>
</persistence-mapping>


Do I have to annotate the whole EPackage or just the EClass that holds the reference?
Re: [CDO/Hibernate/Teneo] java.lang.String cannot be cast to java.lang.Long [message #871592 is a reply to message #871561] Mon, 14 May 2012 13:39 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
I think I found it now:

<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo">
	<epackage namespace-uri="http://eclipse.org/graphiti/mm">
		<any-meta-def id-type="string" meta-type="string" />
	</epackage>
	<epackage namespace-uri="http://eclipse.org/graphiti/mm/pictograms">
		<any-meta-def id-type="string" meta-type="string" />
	</epackage>
	<epackage namespace-uri="http://eclipse.org/graphiti/mm/algorithms">
		<any-meta-def id-type="string" meta-type="string" />
	</epackage>
	<epackage namespace-uri="http://eclipse.org/graphiti/mm/algorithms/styles">
		<any-meta-def id-type="string" meta-type="string" />
	</epackage>
</persistence-mapping>


I have edited the config wiki to use a fragment instead of an additional plugin to register the xml file:

http://wiki.eclipse.org/CDO/Hibernate_Store/Configuration_and_Setup#Additional_Hibernate_or_other_Config_files
Re: [CDO/Hibernate/Teneo] java.lang.String cannot be cast to java.lang.Long [message #871604 is a reply to message #871592] Mon, 14 May 2012 14:07 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
Unfortunately, that did not change anything... I have this EClass:

    <eClassifiers xsi:type="ecore:EClass" name="PictogramLink" eSuperTypes="#//PropertyContainer">
      <eStructuralFeatures xsi:type="ecore:EReference" name="pictogramElement" ordered="false"
          unique="false" eType="#//pictograms/PictogramElement" eOpposite="#//pictograms/PictogramElement/link"/>
      <eStructuralFeatures xsi:type="ecore:EReference" name="businessObjects" upperBound="-1"
          eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EObject"/>
    </eClassifiers>


A table "pictogramlink_businessobjects" with 3 columns will be generated:
- pictogramlink_e_id numeric
- businessobjects_type varchar
- businessobjects_id numeric

How would I configure the xml to tell teneo to make the type of column businessobjects_id a varchar (String)?
Re: [CDO/Hibernate/Teneo] java.lang.String cannot be cast to java.lang.Long [message #871619 is a reply to message #871604] Mon, 14 May 2012 14:29 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Erdal,
Are you sure that the xml file with the additional annotations is read?

gr. Martin

On 05/14/2012 04:07 PM, Erdal Karaca wrote:
> Unfortunately, that did not change anything... I have this EClass:
>
>
> <eClassifiers xsi:type="ecore:EClass" name="PictogramLink" eSuperTypes="#//PropertyContainer">
> <eStructuralFeatures xsi:type="ecore:EReference" name="pictogramElement" ordered="false"
> unique="false" eType="#//pictograms/PictogramElement" eOpposite="#//pictograms/PictogramElement/link"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="businessObjects" upperBound="-1"
> eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EObject"/>
> </eClassifiers>
>
>
> A table "pictogramlink_businessobjects" with 3 columns will be generated:
> - pictogramlink_e_id numeric
> - businessobjects_type varchar
> - businessobjects_id numeric
>
> How would I configure the xml to tell teneo to make the type of column businessobjects_id a varchar (String)?
>


--

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: [CDO/Hibernate/Teneo] java.lang.String cannot be cast to java.lang.Long [message #871622 is a reply to message #871619] Mon, 14 May 2012 14:44 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
Yes, cdo says that it cannot find the (graphiti) packages, but I am allowed to ignore it if the packages are registered later... And that is the case, they are registered when specific instances of the graphiti packages are serialized:

!MESSAGE No EPackage found for namespace http://eclipse.org/graphiti/mm/algorithms/styles. This is not a problem if this EPackage is registered later.

[same for other graphiti epackages]


And I have debugged down to the location where the xml file is read and parsed: org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingBuilder.buildMapping(List<EPackage>, PersistenceOptions, ExtensionManager)
Re: [CDO/Hibernate/Teneo] java.lang.String cannot be cast to java.lang.Long [message #871629 is a reply to message #871622] Mon, 14 May 2012 15:03 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Erdal,
Looking back at the xml, I think it is wrong, the any-metadef should be on a property/ereference not on epackage level.

This zip file contains several examples on how to do things in xml:
http://wiki.eclipse.org/images/4/48/Teneo_XML_Annotations_Examples.zip

gr. Martin

On 05/14/2012 04:44 PM, Erdal Karaca wrote:
> Yes, cdo says that it cannot find the (graphiti) packages, but I am allowed to ignore it if the packages are registered
> later... And that is the case, they are registered when specific instances of the graphiti packages are serialized:
>
>
> !MESSAGE No EPackage found for namespace http://eclipse.org/graphiti/mm/algorithms/styles. This is not a problem if this
> EPackage is registered later.
>
> [same for other graphiti epackages]
>
>
> And I have debugged down to the location where the xml file is read and parsed:
> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingBuilder.buildMapping(List<EPackage>, PersistenceOptions,
> ExtensionManager)


--

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: [CDO/Hibernate/Teneo] java.lang.String cannot be cast to java.lang.Long [message #871632 is a reply to message #871629] Mon, 14 May 2012 15:22 Go to previous message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
Thanks very much, Martin. That solved it:

<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 persistence-mapping-hibernate.xsd">
	<epackage namespace-uri="http://eclipse.org/graphiti/mm/pictograms">
		<eclass name="PictogramLink">
			<ereference name="businessObjects">
				<any-meta-def id-type="string" meta-type="string"></any-meta-def>
			</ereference>
		</eclass>
	</epackage>
</persistence-mapping>

Previous Topic:Texo: how to annotate all tables: prefix for tables in db
Next Topic:[EMF XML] : NPE on saving with OPTION_USE_CACHED_LOOKUP_TABLE and OPTION_EXTENDED_META_DATA option
Goto Forum:
  


Current Time: Thu Apr 25 20:48:02 GMT 2024

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

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

Back to the top