Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [CDO] [Teneo] Default enum value persisted as NULL
[CDO] [Teneo] Default enum value persisted as NULL [message #1198830] Wed, 20 November 2013 14:31 Go to next message
Oskar Maxa is currently offline Oskar MaxaFriend
Messages: 4
Registered: November 2013
Junior Member
Hello,

I'm using CDO 4.2.1 with the Hibernate Store (Teneo 2.0.1, Hibernate 4.1.1) with MySQL behind it.

I have an enum defined in an xcore file and to my dismay, its first value is being persisted as NULL in the MySQL database. This is ok when working with the CDO object graph, as the NULL values are apparently transparently converted (by Teneo?) into the appropriate enum values when read, but it becomes a problem when using HQL which sees the nulls.

Below is an xcore snippet:

class User {
  UserStatus status
}

enum UserStatus {
  Enabled = 0
  Disabled = 1
  Deleted = 2
}


First, I create a bunch of users with random status values. Then, in MySQL, I can see that the status column is set to "Disabled" or "Deleted" for some rows, and NULL for the rest. And when I execute the query "select u from User u where u.status = 'Enabled'", I get nothing, and I have to use "u.status is null" instead.

And it gets worse when trying to filter with "where u.status != 'Deleted'", which has to become "where u.status is null or u.status != 'Deleted'" in order to work.

How can I get the Hibernate Store to persist all enum values as their respective literals?

I found this bug page and thought the config option mentioned there might help, but it didn't: https://bugs.eclipse.org/bugs/show_bug.cgi?id=279375


EDIT: If I define the enum without the numerical values (as shown below), things get stranger. Enabled again becomes NULL in the MySQL database, but both Disabled and Deleted are persisted as "Enabled".
enum UserStatus {
  Enabled
  Disabled
  Deleted
}

[Updated on: Wed, 20 November 2013 19:32]

Report message to a moderator

Re: [CDO] [Teneo] Default enum value persisted as NULL [message #1199485 is a reply to message #1198830] Wed, 20 November 2013 21:41 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Oskar,
Hmm, this option is being used in the code. Can you try to debug in the code? This can be done with a breakpoint in
CDOPropertyGetter the get method. This Class/method is used by Hibernate to determine what value should be stored in the
database.
There will be an instance of CDOPropertyGetter for each EAttribute. You can also check out the value handleUnsetAsNull
member of this class, it should be false in your case.

Let me know what you find.

gr. Martin

On 11/20/2013 04:45 PM, Oskar Maxa wrote:
> I'm using CDO with the Hibernate Store with MySQL behind it.
>
> I have an enum defined in an xcore file and to my dismay, its first value is being persisted as NULL in the MySQL
> database. This is ok when working with the CDO object graph, as the NULL values are apparently transparently converted
> (by Teneo?) into the appropriate enum values when read, but it becomes a problem when using HQL which sees the nulls.
>
> Below is an xcore snippet:
>
>
> class User {
> UserStatus status
> }
>
> enum UserStatus {
> Enabled = 0
> Disabled = 1
> Deleted = 2
> }
>
>
> First, I create a bunch of users with random status values. Then, in MySQL, I can see that the status column is set to
> Disabled or Deleted for some rows, and NULL for the rest. And when I execute the query "select u from User u where
> u.status = 'Enabled'", I get nothing, and I have to use "u.status is null" instead.
>
> And it gets worse when trying to filter with "where u.status != 'Deleted'", which has to become "where u.status is null
> or u.status != 'Deleted'" in order to work.
>
> How can I get the Hibernate Store to persist all enum values as their respective literals?
>
> I found this bug page and thought the config option mentioned there might help, but it didn't:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=279375


--

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] [Teneo] Default enum value persisted as NULL [message #1200540 is a reply to message #1199485] Thu, 21 November 2013 09:38 Go to previous messageGo to next message
Oskar Maxa is currently offline Oskar MaxaFriend
Messages: 4
Registered: November 2013
Junior Member
Hi Martin, here's what I found:

When CDOPropertyGetter.get is passed a user as the target parameter, the target.values field has a null entry for the status if it was set to Enabled, and 1 (Integer) if it was set to Disabled. In the former case, control goes through the whole method and null is returned by the "return value;" statement at the end.

I also confirmed that changing the value of teneo.runtime.handle_unset_as_null affects the value of CDOPropertyGetter.handleUnsetAsNull. However, the behavior is the same whether it's true or false.

For what it's worth, I'm setting the status like this:
user.setStatus(UserStatus.ENABLED);
Re: [CDO] [Teneo] Default enum value persisted as NULL [message #1200716 is a reply to message #1200540] Thu, 21 November 2013 11:24 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Oskar,
It should get into this code:

// this happens when you don't set a value explicitly in CDO
// then null is passed while the user may expect the default
// value to be set.
if (useDefaultValue())

so call useDefaultValue, in your case this seems to return false, does it?
Is the feature unsettable?

gr. Martin

On 11/21/2013 10:38 AM, Oskar Maxa wrote:
> Hi Martin, here's what I found:
>
> When CDOPropertyGetter.get is passed a user as the target parameter, the target.values field has a null entry for the
> status if it was set to Enabled, and 1 (Integer) if it was set to Disabled. In the former case, control goes through the
> whole method and null is returned by the "return value;" statement at the end.
>
> I also confirmed that changing the value of teneo.runtime.handle_unset_as_null affects the value of
> CDOPropertyGetter.handleUnsetAsNull. However, the behavior is the same whether it's true or false.
>
> For what it's worth, I'm setting the status like this:
> user.setStatus(UserStatus.ENABLED);


--

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] [Teneo] Default enum value persisted as NULL [message #1200876 is a reply to message #1200716] Thu, 21 November 2013 13:08 Go to previous messageGo to next message
Oskar Maxa is currently offline Oskar MaxaFriend
Messages: 4
Registered: November 2013
Junior Member
Yes, useDefaultValue() returns false because the feature is not unsettable. However, when I make it unsettable (until now I didn't know there was such an option), the problem disappears and all values are persisted as they should, which is great.

The question now is, do I have to leave it like this for it to work, or is there another solution? User.status being unsettable doesn't make sense from a modelling perspective. Also, is the behavior I encountered intended or a bug?
Re: [CDO] [Teneo] Default enum value persisted as NULL [message #1200965 is a reply to message #1200876] Thu, 21 November 2013 14:01 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Oskar,
Hmm yes, there has been long and frequent discussions on enums and default value handling... It seems very simple (also
with the unsettable concept) but it is not. It originates from xml with elements which can not be present in the xml
document, or can have no value, also EMF assumes that enums are primitive values which always have a value (like an int
or a double always have a value zero).

See these 2 discussions:
http://www.eclipse.org/forums/index.php?t=msg&th=128532/
http://www.eclipse.org/forums/index.php?t=msg&th=136337/
http://www.eclipse.org/forums/index.php?t=tree&th=161533&#page_top

(and many more :-)

Probably it would be best if I would introduce a separate option in Teneo to handle Enums specifically so that they are
correctly handled even in case unsettable is false. You can enter a bugzilla on Teneo for this if you want.

But for now I would keep your feature unsettable...

gr. Martin


On 11/21/2013 02:08 PM, Oskar Maxa wrote:
> Yes, useDefaultValue() returns false because the feature is not unsettable. However, when I make it unsettable (until
> now I didn't know there was such an option), the problem disappears and all values are persisted as they should, which
> is great.
>
> The question now is, do I have to leave it like this for it to work, or is there another solution? User.status being
> unsettable doesn't make sense from a modelling perspective. Also, is the behavior I encountered intended or a bug?


--

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] [Teneo] Default enum value persisted as NULL [message #1209562 is a reply to message #1200965] Mon, 25 November 2013 15:34 Go to previous message
Oskar Maxa is currently offline Oskar MaxaFriend
Messages: 4
Registered: November 2013
Junior Member
Hi Martin,

I created a bug report here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=422480

I will keep the feature unsettable in the meantime, as you suggest.

Thanks for your help.

Regards,
Oskar
Previous Topic:[Texo] Unset value/Update query
Next Topic:EcoreUtil.copy() for bidirectional references
Goto Forum:
  


Current Time: Sat Feb 27 10:35:35 GMT 2021

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

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

Back to the top