Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO/Hibernate] Problem with Enum Attributes
[CDO/Hibernate] Problem with Enum Attributes [message #940428] Thu, 11 October 2012 12:21 Go to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 328
Registered: December 2010
Location: Germany
Senior Member
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 Smile)

Greetings
Christoph
Re: [CDO/Hibernate] Problem with Enum Attributes [message #941082 is a reply to message #940428] Fri, 12 October 2012 03:47 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5325
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 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5325
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 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5325
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 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5325
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 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5325
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 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5325
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 #941128 is a reply to message #941111] Fri, 12 October 2012 04:33 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 328
Registered: December 2010
Location: Germany
Senior Member
Hi Martin

Yeah. I see it.

Would you send me the model you are using for these test? I would like to run your test on my server configuration and see if that will work ... or not ...

Greetings
Christoph
Re: [CDO] Problem with Enum Attributes [message #941166 is a reply to message #941128] Fri, 12 October 2012 05:07 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 328
Registered: December 2010
Location: Germany
Senior Member
Hi Martin

I found the model in cdo.test.hibernate. Trying to get the tests to tun ...

Greetings
Christoph
Re: [CDO] Problem with Enum Attributes [message #941442 is a reply to message #941166] Fri, 12 October 2012 10:26 Go to previous message
Christoph Keimel is currently offline Christoph Keimel
Messages: 328
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.
Previous Topic:EMF Validation in Eclipse 3.8
Next Topic:Defining which derived class a feature from an abstract class shall use
Goto Forum:
  


Current Time: Tue Jul 22 09:35:15 EDT 2014

Powered by FUDForum. Page generated in 0.03095 seconds