Home » Modeling » EMF » [CDO/Hibernate] Problem with Enum Attributes
|
| Re: [CDO/Hibernate] Problem with Enum Attributes [message #941082 is a reply to message #940428] |
Fri, 12 October 2012 03:47   |
Martin Taal Messages: 5054 Registered: July 2009 |
Senior Member |
|
|
Hi Christoph,
I can't really explain this... I have a testcase for this also, I adapted it a little to really check. See the attached
code look for VAT7 and VAT15 to see the enums.
gr. Martin
On 10/11/2012 06:21 PM, Christoph Keimel wrote:
> Hello
>
> I am having a problem with enum attributes.
>
> Using this test model:
> enum SomeEnum {
> FIRST
> SECOND
> THIRD
> }
>
> class ElementWithEnum {
> String[1] name
> SomeEnum[1] some
> }
> ... running this code ...
> public void execute(IRepoService repo) {
> CDOTransaction transaction = repo.openTransaction();
> try {
> CDOResource res = transaction.getRootResource();
>
> ElementWithEnum element = EmTracFactory.eINSTANCE.createElementWithEnum();
> element.setName("Test element " + res.getContents().size());
> logger.info("some (Default): {}", element.getSome());
>
> SomeEnum toSet = SomeEnum.SECOND;
> element.setSome(toSet);
> logger.info("some (After Set): {}", element.getSome());
>
> res.getContents().add(element);
> transaction.commit();
> logger.info("some (After Commit): {}", element.getSome());
>
> Assert.isTrue(toSet == element.getSome());
> } catch (CommitException e) {
> logger.error("CommitException: {}", e);
> } finally {
> transaction.close();
> }
> }
> where IRepoService is just a simple wrapper managing the connection to the server with a single CDOSession.
>
> I get the following log output:
> 18:13:41.353 INFO d.e.e.c.t.h.TestInsertElementWithEnum - some (Default): FIRST
> 18:13:41.353 INFO d.e.e.c.t.h.TestInsertElementWithEnum - some (After Set): SECOND
> 18:13:41.384 INFO d.e.e.c.t.h.TestInsertElementWithEnum - some (After Commit): FIRST
> and the Assert.isTrue fails because the attribute some now has its default value again.
>
> This seems so basic, that I suspect that I am missing something realy fundamental, but I have no idea what it could be.
> Please help! (again :))
>
> Greetings
> Christoph
--
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] Problem with Enum Attributes [message #941086 is a reply to message #940428] |
Fri, 12 October 2012 03:47   |
Martin Taal Messages: 5054 Registered: July 2009 |
Senior Member |
|
|
Hi Christoph,
I can't really explain this... I have a testcase for this also, I adapted it a little to really check. See the attached
code look for VAT7 and VAT15 to see the enums.
gr. Martin
On 10/11/2012 06:21 PM, Christoph Keimel wrote:
> Hello
>
> I am having a problem with enum attributes.
>
> Using this test model:
> enum SomeEnum {
> FIRST
> SECOND
> THIRD
> }
>
> class ElementWithEnum {
> String[1] name
> SomeEnum[1] some
> }
> ... running this code ...
> public void execute(IRepoService repo) {
> CDOTransaction transaction = repo.openTransaction();
> try {
> CDOResource res = transaction.getRootResource();
>
> ElementWithEnum element = EmTracFactory.eINSTANCE.createElementWithEnum();
> element.setName("Test element " + res.getContents().size());
> logger.info("some (Default): {}", element.getSome());
>
> SomeEnum toSet = SomeEnum.SECOND;
> element.setSome(toSet);
> logger.info("some (After Set): {}", element.getSome());
>
> res.getContents().add(element);
> transaction.commit();
> logger.info("some (After Commit): {}", element.getSome());
>
> Assert.isTrue(toSet == element.getSome());
> } catch (CommitException e) {
> logger.error("CommitException: {}", e);
> } finally {
> transaction.close();
> }
> }
> where IRepoService is just a simple wrapper managing the connection to the server with a single CDOSession.
>
> I get the following log output:
> 18:13:41.353 INFO d.e.e.c.t.h.TestInsertElementWithEnum - some (Default): FIRST
> 18:13:41.353 INFO d.e.e.c.t.h.TestInsertElementWithEnum - some (After Set): SECOND
> 18:13:41.384 INFO d.e.e.c.t.h.TestInsertElementWithEnum - some (After Commit): FIRST
> and the Assert.isTrue fails because the attribute some now has its default value again.
>
> This seems so basic, that I suspect that I am missing something realy fundamental, but I have no idea what it could be.
> Please help! (again :))
>
> Greetings
> Christoph
--
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] Problem with Enum Attributes [message #941091 is a reply to message #940428] |
Fri, 12 October 2012 03:47   |
Martin Taal Messages: 5054 Registered: July 2009 |
Senior Member |
|
|
Hi Christoph,
I can't really explain this... I have a testcase for this also, I adapted it a little to really check. See the attached
code look for VAT7 and VAT15 to see the enums.
gr. Martin
On 10/11/2012 06:21 PM, Christoph Keimel wrote:
> Hello
>
> I am having a problem with enum attributes.
>
> Using this test model:
> enum SomeEnum {
> FIRST
> SECOND
> THIRD
> }
>
> class ElementWithEnum {
> String[1] name
> SomeEnum[1] some
> }
> ... running this code ...
> public void execute(IRepoService repo) {
> CDOTransaction transaction = repo.openTransaction();
> try {
> CDOResource res = transaction.getRootResource();
>
> ElementWithEnum element = EmTracFactory.eINSTANCE.createElementWithEnum();
> element.setName("Test element " + res.getContents().size());
> logger.info("some (Default): {}", element.getSome());
>
> SomeEnum toSet = SomeEnum.SECOND;
> element.setSome(toSet);
> logger.info("some (After Set): {}", element.getSome());
>
> res.getContents().add(element);
> transaction.commit();
> logger.info("some (After Commit): {}", element.getSome());
>
> Assert.isTrue(toSet == element.getSome());
> } catch (CommitException e) {
> logger.error("CommitException: {}", e);
> } finally {
> transaction.close();
> }
> }
> where IRepoService is just a simple wrapper managing the connection to the server with a single CDOSession.
>
> I get the following log output:
> 18:13:41.353 INFO d.e.e.c.t.h.TestInsertElementWithEnum - some (Default): FIRST
> 18:13:41.353 INFO d.e.e.c.t.h.TestInsertElementWithEnum - some (After Set): SECOND
> 18:13:41.384 INFO d.e.e.c.t.h.TestInsertElementWithEnum - some (After Commit): FIRST
> and the Assert.isTrue fails because the attribute some now has its default value again.
>
> This seems so basic, that I suspect that I am missing something realy fundamental, but I have no idea what it could be.
> Please help! (again :))
>
> Greetings
> Christoph
--
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] Problem with Enum Attributes [message #941099 is a reply to message #940428] |
Fri, 12 October 2012 03:47   |
Martin Taal Messages: 5054 Registered: July 2009 |
Senior Member |
|
|
Hi Christoph,
I can't really explain this... I have a testcase for this also, I adapted it a little to really check. See the attached
code look for VAT7 and VAT15 to see the enums.
gr. Martin
On 10/11/2012 06:21 PM, Christoph Keimel wrote:
> Hello
>
> I am having a problem with enum attributes.
>
> Using this test model:
> enum SomeEnum {
> FIRST
> SECOND
> THIRD
> }
>
> class ElementWithEnum {
> String[1] name
> SomeEnum[1] some
> }
> ... running this code ...
> public void execute(IRepoService repo) {
> CDOTransaction transaction = repo.openTransaction();
> try {
> CDOResource res = transaction.getRootResource();
>
> ElementWithEnum element = EmTracFactory.eINSTANCE.createElementWithEnum();
> element.setName("Test element " + res.getContents().size());
> logger.info("some (Default): {}", element.getSome());
>
> SomeEnum toSet = SomeEnum.SECOND;
> element.setSome(toSet);
> logger.info("some (After Set): {}", element.getSome());
>
> res.getContents().add(element);
> transaction.commit();
> logger.info("some (After Commit): {}", element.getSome());
>
> Assert.isTrue(toSet == element.getSome());
> } catch (CommitException e) {
> logger.error("CommitException: {}", e);
> } finally {
> transaction.close();
> }
> }
> where IRepoService is just a simple wrapper managing the connection to the server with a single CDOSession.
>
> I get the following log output:
> 18:13:41.353 INFO d.e.e.c.t.h.TestInsertElementWithEnum - some (Default): FIRST
> 18:13:41.353 INFO d.e.e.c.t.h.TestInsertElementWithEnum - some (After Set): SECOND
> 18:13:41.384 INFO d.e.e.c.t.h.TestInsertElementWithEnum - some (After Commit): FIRST
> and the Assert.isTrue fails because the attribute some now has its default value again.
>
> This seems so basic, that I suspect that I am missing something realy fundamental, but I have no idea what it could be.
> Please help! (again :))
>
> Greetings
> Christoph
--
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] Problem with Enum Attributes [message #941104 is a reply to message #940428] |
Fri, 12 October 2012 03:47   |
Martin Taal Messages: 5054 Registered: July 2009 |
Senior Member |
|
|
Hi Christoph,
I can't really explain this... I have a testcase for this also, I adapted it a little to really check. See the attached
code look for VAT7 and VAT15 to see the enums.
gr. Martin
On 10/11/2012 06:21 PM, Christoph Keimel wrote:
> Hello
>
> I am having a problem with enum attributes.
>
> Using this test model:
> enum SomeEnum {
> FIRST
> SECOND
> THIRD
> }
>
> class ElementWithEnum {
> String[1] name
> SomeEnum[1] some
> }
> ... running this code ...
> public void execute(IRepoService repo) {
> CDOTransaction transaction = repo.openTransaction();
> try {
> CDOResource res = transaction.getRootResource();
>
> ElementWithEnum element = EmTracFactory.eINSTANCE.createElementWithEnum();
> element.setName("Test element " + res.getContents().size());
> logger.info("some (Default): {}", element.getSome());
>
> SomeEnum toSet = SomeEnum.SECOND;
> element.setSome(toSet);
> logger.info("some (After Set): {}", element.getSome());
>
> res.getContents().add(element);
> transaction.commit();
> logger.info("some (After Commit): {}", element.getSome());
>
> Assert.isTrue(toSet == element.getSome());
> } catch (CommitException e) {
> logger.error("CommitException: {}", e);
> } finally {
> transaction.close();
> }
> }
> where IRepoService is just a simple wrapper managing the connection to the server with a single CDOSession.
>
> I get the following log output:
> 18:13:41.353 INFO d.e.e.c.t.h.TestInsertElementWithEnum - some (Default): FIRST
> 18:13:41.353 INFO d.e.e.c.t.h.TestInsertElementWithEnum - some (After Set): SECOND
> 18:13:41.384 INFO d.e.e.c.t.h.TestInsertElementWithEnum - some (After Commit): FIRST
> and the Assert.isTrue fails because the attribute some now has its default value again.
>
> This seems so basic, that I suspect that I am missing something realy fundamental, but I have no idea what it could be.
> Please help! (again :))
>
> Greetings
> Christoph
--
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] Problem with Enum Attributes [message #941111 is a reply to message #940428] |
Fri, 12 October 2012 03:47   |
Martin Taal Messages: 5054 Registered: July 2009 |
Senior Member |
|
|
Hi Christoph,
I can't really explain this... I have a testcase for this also, I adapted it a little to really check. See the attached
code look for VAT7 and VAT15 to see the enums.
gr. Martin
On 10/11/2012 06:21 PM, Christoph Keimel wrote:
> Hello
>
> I am having a problem with enum attributes.
>
> Using this test model:
> enum SomeEnum {
> FIRST
> SECOND
> THIRD
> }
>
> class ElementWithEnum {
> String[1] name
> SomeEnum[1] some
> }
> ... running this code ...
> public void execute(IRepoService repo) {
> CDOTransaction transaction = repo.openTransaction();
> try {
> CDOResource res = transaction.getRootResource();
>
> ElementWithEnum element = EmTracFactory.eINSTANCE.createElementWithEnum();
> element.setName("Test element " + res.getContents().size());
> logger.info("some (Default): {}", element.getSome());
>
> SomeEnum toSet = SomeEnum.SECOND;
> element.setSome(toSet);
> logger.info("some (After Set): {}", element.getSome());
>
> res.getContents().add(element);
> transaction.commit();
> logger.info("some (After Commit): {}", element.getSome());
>
> Assert.isTrue(toSet == element.getSome());
> } catch (CommitException e) {
> logger.error("CommitException: {}", e);
> } finally {
> transaction.close();
> }
> }
> where IRepoService is just a simple wrapper managing the connection to the server with a single CDOSession.
>
> I get the following log output:
> 18:13:41.353 INFO d.e.e.c.t.h.TestInsertElementWithEnum - some (Default): FIRST
> 18:13:41.353 INFO d.e.e.c.t.h.TestInsertElementWithEnum - some (After Set): SECOND
> 18:13:41.384 INFO d.e.e.c.t.h.TestInsertElementWithEnum - some (After Commit): FIRST
> and the Assert.isTrue fails because the attribute some now has its default value again.
>
> This seems so basic, that I suspect that I am missing something realy fundamental, but I have no idea what it could be.
> Please help! (again :))
>
> Greetings
> Christoph
--
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] Problem with Enum Attributes [message #941442 is a reply to message #941166] |
Fri, 12 October 2012 10:26  |
Christoph Keimel Messages: 277 Registered: December 2010 Location: Germany |
Senior Member |
|
|
Hi Everybody
I found the problem while debugging Martins test code. The issue comes from the Xcore definition of the enum:
enum SomeEnum {
FIRST
SECOND
THIRD
}
Defined like this every item (FRIST, SEOND, THIRD) has the same ecore "value" property: 0. In this case CDO tries to save this as a String literal ("FIRST, "SECOND", "THIRD"), but that doesn't survive the commit.
The solution is to define the values like this, so that CDO can use the Integer value:
enum SomeEnum {
FIRST = 0
SECOND = 1
THIRD = 2
}
Voila!
@Martin: Thanks for the support.
Greetings
Christoph
P.S. The issue is the same when using the DBStore, so it wasn't realy Hibernate related ... hence the change in the title of this topic.
|
|
|
Goto Forum:
Current Time: Fri May 24 19:00:25 EDT 2013
Powered by FUDForum. Page generated in 0.01876 seconds
|