Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Nullable does not work
Nullable does not work [message #116271] Thu, 27 March 2008 20:24 Go to next message
Manfred Hahn is currently offline Manfred HahnFriend
Messages: 64
Registered: July 2009
Member
Hi Martin,

I try to set a column to not-null="true" in the hibernate mapping file by
setting an @Column annotation.
In the ecore file it looks like this:

<eAnnotations source="teneo.jpa">
<details key="appinfo" value="@Column(name=&quot;test&quot;
nullable=&quot;false&quot;)"/>
</eAnnotations>

The property is a simple field in an abstract superclass. The name
attribute I set for test purposes (as the value implies..;-).

The hibernate mapping looks like this:

<column not-null="false" unique="false" name="`test`"/>

So the name attribute has been taken over, but the nullable attribute
didn't change anything.
I have tried the 'false' attribute value both with and without quotes.

Did I do something wrong?

With regards

Manfred
Re: Nullable does not work [message #116284 is a reply to message #116271] Thu, 27 March 2008 20:39 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Manfred,
Yes in the code it is done like this:
private boolean isNullable(Basic basic, PAnnotatedEAttribute aattr) {
return getHbmContext().isForceOptional() || basic.isOptional() ||
getHbmContext().isCurrentElementFeatureMap() &&
(aattr.getColumn() == null || aattr.getColumn().isNullable());
}

so if the basic optional annotation says nullable then it is nullable, the default value for the
basic.optional is true. If you don't specify a column annotation then setting basic.optional to
false will work. If you have both a basic and a column annotation then basic.optional should be
false as well as column.nullable should be false.

Looking again at the ejb3 spec I am not sure if the above is really the best behavior. I think the
column annotation should determine nullability on column level and the basic.optional can be used as
a default.
Can you enter a bugzilla for this?

In the mean time the easy workaround is adding this annotation:
@Basic(optional=false)

gr. Martin

Manfred Hahn wrote:
> Hi Martin,
>
> I try to set a column to not-null="true" in the hibernate mapping file
> by setting an @Column annotation.
> In the ecore file it looks like this:
>
> <eAnnotations source="teneo.jpa">
> <details key="appinfo" value="@Column(name=&quot;test&quot;
> nullable=&quot;false&quot;)"/>
> </eAnnotations>
>
> The property is a simple field in an abstract superclass. The name
> attribute I set for test purposes (as the value implies..;-).
>
> The hibernate mapping looks like this:
>
> <column not-null="false" unique="false" name="`test`"/>
>
> So the name attribute has been taken over, but the nullable attribute
> didn't change anything.
> I have tried the 'false' attribute value both with and without quotes.
>
> Did I do something wrong?
>
> With regards
>
> Manfred
>
>
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: Nullable does not work [message #616021 is a reply to message #116271] Thu, 27 March 2008 20:39 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Manfred,
Yes in the code it is done like this:
private boolean isNullable(Basic basic, PAnnotatedEAttribute aattr) {
return getHbmContext().isForceOptional() || basic.isOptional() ||
getHbmContext().isCurrentElementFeatureMap() &&
(aattr.getColumn() == null || aattr.getColumn().isNullable());
}

so if the basic optional annotation says nullable then it is nullable, the default value for the
basic.optional is true. If you don't specify a column annotation then setting basic.optional to
false will work. If you have both a basic and a column annotation then basic.optional should be
false as well as column.nullable should be false.

Looking again at the ejb3 spec I am not sure if the above is really the best behavior. I think the
column annotation should determine nullability on column level and the basic.optional can be used as
a default.
Can you enter a bugzilla for this?

In the mean time the easy workaround is adding this annotation:
@Basic(optional=false)

gr. Martin

Manfred Hahn wrote:
> Hi Martin,
>
> I try to set a column to not-null="true" in the hibernate mapping file
> by setting an @Column annotation.
> In the ecore file it looks like this:
>
> <eAnnotations source="teneo.jpa">
> <details key="appinfo" value="@Column(name=&quot;test&quot;
> nullable=&quot;false&quot;)"/>
> </eAnnotations>
>
> The property is a simple field in an abstract superclass. The name
> attribute I set for test purposes (as the value implies..;-).
>
> The hibernate mapping looks like this:
>
> <column not-null="false" unique="false" name="`test`"/>
>
> So the name attribute has been taken over, but the nullable attribute
> didn't change anything.
> I have tried the 'false' attribute value both with and without quotes.
>
> Did I do something wrong?
>
> With regards
>
> Manfred
>
>
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Previous Topic:Nullable does not work
Next Topic:Problem with GenericGenerator annotation
Goto Forum:
  


Current Time: Sat Jul 24 08:39:28 GMT 2021

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

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

Back to the top