MyModel myModel = MyModelFactory.eINSTANCE.createMyModel(); File file = new File(location); try (DataInputStream dis = new DataInputStream(new FileInputStream(file))) { CDOBlob blob = new CDOBlob(dis); myModel.setData(blob); CDOTransaction transaction = null; try { transaction = cdoSession.openTransaction(); CDOResource resource = transaction.getOrCreateResource("/home/mymodel"); resource.getContents().clear(); //clear old data resource.getContents().add(myModel); transaction.commit(); } catch (SecurityException e) { MessageDialog.openError(Display.getCurrent().getActiveShell(), e.getClass().toString(), "Authentification Failed!"); System.exit(0); } catch (CommitException | CDOException e) { //some exception handling } finally { if (transaction != null) { transaction.close(); } } } catch (IOException e1) { //some exception handling }
CDOView view = null; try { view = cdoSession.openView(); CDOResource resource = view.getResource("/home/mymodel"); MyModel test = (MyModel) resource.getContents().get(0); try (InputStream in = test.getData().getContents()) { //<--------------------------- test.getData() is null! byte[] data = new byte[in.available()]; in.read(data); System.out.println(data.length); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (SecurityException e) { MessageDialog.openError(Display.getCurrent().getActiveShell(), e.getClass().toString(), "Authentification Failed!"); System.exit(0); } catch (CDOException e) { //some exception handling } finally { if (view != null) { view.close(); } }
java.lang.ClassCastException: org.eclipse.emf.cdo.etypes.impl.EtypesFactoryImpl cannot be cast to etypes.EtypesFactory at etypes.impl.EtypesFactoryImpl.init(EtypesFactoryImpl.java:31) at etypes.EtypesFactory.<clinit>(EtypesFactory.java:22) at etypes.impl.EtypesPackageImpl.<init>(EtypesPackageImpl.java:102) at etypes.impl.EtypesPackageImpl.init(EtypesPackageImpl.java:128) at etypes.EtypesPackage.<clinit>(EtypesPackage.java:59) at My.impl.MyPackageImpl.init(MyPackageImpl.java:85) at My.MyPackage.<clinit>(MyPackage.java:57) at My.MyPackage$Literals.<clinit>(MyPackage.java:210) at My.impl.MyModelImpl.eStaticClass(MyModelImpl.java:106) at org.eclipse.emf.ecore.impl.MinimalEObjectImpl.eClass(MinimalEObjectImpl.java:688) at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.<init>(CDOLegacyWrapper.java:104) at org.eclipse.emf.internal.cdo.object.CDOLegacyAdapter.<init>(CDOLegacyAdapter.java:51) at org.eclipse.emf.spi.cdo.FSMUtil.adaptLegacy(FSMUtil.java:117) at org.eclipse.emf.spi.cdo.FSMUtil.adapt(FSMUtil.java:101) at org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl$ContentsCDOList.inverseAdd(CDOResourceImpl.java:1760) at org.eclipse.emf.common.notify.impl.DelegatingNotifyingListImpl.addUnique(DelegatingNotifyingListImpl.java:304) at org.eclipse.emf.common.util.AbstractEList.add(AbstractEList.java:303) at test.standalone.application.util.MyImporter$ImportThread.run(MyImporter.java:143) at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:122)
> Have you tried to add myModel to the resource first and then set the blob attribute?
I tried this, but the behavior is the same.
> What's the stack trace?
java.lang.ClassCastException: org.eclipse.emf.cdo.etypes.impl.EtypesFactoryImpl cannot be cast to etypes.EtypesFactory at etypes.impl.EtypesFactoryImpl.init(EtypesFactoryImpl.java:31) at etypes.EtypesFactory.<clinit>(EtypesFactory.java:22) at etypes.impl.EtypesPackageImpl.<init>(EtypesPackageImpl.java:102) at etypes.impl.EtypesPackageImpl.init(EtypesPackageImpl.java:128) at etypes.EtypesPackage.<clinit>(EtypesPackage.java:59) at My.impl.MyPackageImpl.init(MyPackageImpl.java:85) at My.MyPackage.<clinit>(MyPackage.java:57) at My.MyPackage$Literals.<clinit>(MyPackage.java:210) at My.impl.MyModelImpl.eStaticClass(MyModelImpl.java:106) at org.eclipse.emf.ecore.impl.MinimalEObjectImpl.eClass(MinimalEObjectImpl.java:688) at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.<init>(CDOLegacyWrapper.java:104) at org.eclipse.emf.internal.cdo.object.CDOLegacyAdapter.<init>(CDOLegacyAdapter.java:51) at org.eclipse.emf.spi.cdo.FSMUtil.adaptLegacy(FSMUtil.java:117) at org.eclipse.emf.spi.cdo.FSMUtil.adapt(FSMUtil.java:101) at org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl$ContentsCDOList.inverseAdd(CDOResourceImpl.java:1760) at org.eclipse.emf.common.notify.impl.DelegatingNotifyingListImpl.addUnique(DelegatingNotifyingListImpl.java:304) at org.eclipse.emf.common.util.AbstractEList.add(AbstractEList.java:303) at test.standalone.application.util.MyImporter$ImportThread.run(MyImporter.java:143) at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:122)
Did you "include" or "reference" etypes.ecore?
It seems that you have included etypes.ecore to your own ecore file, so the editor has generated code for etypes.ecore.
Sometimes I am confused, but in this case it might also be the case that particular statements were made in before the actual etype.ecore model was changed. Since 2016-10-06 the data types Blob and Clob are serializeable and can (and probably should) be used with non-transient attributes. Is that what you concluded, too?