| Nullable does not work [message #116271] |
Thu, 27 March 2008 16:24  |
Eclipse User |
|
|
|
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="test"
nullable="false")"/>
</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 16:39  |
Eclipse User |
|
|
|
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="test"
> nullable="false")"/>
> </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 16:39  |
Eclipse User |
|
|
|
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="test"
> nullable="false")"/>
> </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
|
|
|
Powered by
FUDForum. Page generated in 0.03315 seconds