openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dick <michael.d.d...@gmail.com>
Subject Re: @Basic (optional=false) not mapped to NOT NULL
Date Fri, 19 Nov 2010 22:45:05 GMT
You're correct, @Column(nullable=false) is probably what the original poster
wants.

A good way to think of the two is in their scope. The optional attribute
pertains to the field or attribute on your entity.JPA providers can use this
at runtime to determine whether your object model is consistent. For example
OpenJPA uses it to determine whether it's safe to use an inner join instead
of an outer join.

@Column(nullable=true|false) is used to indicate the database schema - in
OpenJPA it's used primarily for schema generation.

The answer to this
question<http://stackoverflow.com/questions/2899073/basicoptional-false-vs-columnnullable-false-in-jpa>on
StackOverflow covers it well (originally answered by Gordon York).

Hope this helps,
-mike

On Fri, Nov 19, 2010 at 2:10 PM, ljnelson <ljnelson@gmail.com> wrote:

>
> For reasons that have never been clear to me, @Basic(optional = false) does
> not affect column nullability.  I am actually completely uncertain as to
> what it DOES do.
>
> You want:
>
> @Column(name = "url", nullable = false)
>
> Best,
> Laird
>
> On Fri, Nov 19, 2010 at 3:08 PM, Radim Kolář [via OpenJPA] <
> ml-node+5756491-910138721-155969@n2.nabble.com<ml-node%2B5756491-910138721-155969@n2.nabble.com>
> <ml-node%2B5756491-910138721-155969@n2.nabble.com<ml-node%252B5756491-910138721-155969@n2.nabble.com>
> >
> > wrote:
>
> > I have following entity class:
> >
> > @Entity
> > @Table(name="queue")
> >
> > public class QueueEntry {
> >
> >         @Id
> >         @GeneratedValue
> >         private int id;
> >
> >         @Basic(optional=false)
> >         private String url;
> >
> >         @Version
> >         private long version;
> > }
> >
> > SQL statement used for table creation (i use H2 database) is:
> > CREATE TABLE queue (id INTEGER NOT NULL, URL VARCHAR(255), version
> INTEGER,
> > PRIMARY KEY (id));
> >
> > note NOT NULL on URL column is missing.
> >
> > ------------------------------
> >  View message @
> >
> http://openjpa.208410.n2.nabble.com/Basic-optional-false-not-mapped-to-NOT-NULL-tp5756491p5756491.html
> > To start a new topic under OpenJPA Users, email
> > ml-node+208411-242897574-155969@n2.nabble.com<ml-node%2B208411-242897574-155969@n2.nabble.com>
> <ml-node%2B208411-242897574-155969@n2.nabble.com<ml-node%252B208411-242897574-155969@n2.nabble.com>
> >
> > To unsubscribe from OpenJPA Users, click here<
> http://openjpa.208410.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=208411&code=bGpuZWxzb25AZ21haWwuY29tfDIwODQxMXw4OTk4MzY1OTI=
> >.
> >
> >
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Basic-optional-false-not-mapped-to-NOT-NULL-tp5756491p5756496.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message