We are evaluating jooq for our application and want to use the *POJO/DAO 
pattern* in favor of the Record pattern (bean validation annotations, jruby 
integration)

As I was writing tests I had the following situation:

My DB (*Postgres*) table DDL is:

CREATE TABLE users
(
  id serial NOT NULL,
  account_id integer NOT NULL,
  email character varying(255) NOT NULL,
  username character varying(255) NOT NULL,
  locale character varying(255) NOT NULL *DEFAULT 'en'::character varying*,
  time_zone character varying(255) NOT NULL *DEFAULT 'UTC'::character 
varying*,
  first_name character varying(255),
  last_name character varying(255),
  [...]
  CONSTRAINT users_pkey PRIMARY KEY (id )
)
WITH (
  OIDS=FALSE
);



As can see the column "locale" (besides others) has a *default value*.

The generated POJO method is:


            @javax.persistence.Column(name = "locale", nullable = false, 
length = 255)
@javax.validation.constraints.NotNull
@javax.validation.constraints.Size(max = 255)
public java.lang.String getLocale() {
return this.locale;
}


When I want to insert a user now:

              Users user = new Users();

   user.setCreatedAt(now());
   user.setUpdatedAt(now());
   // setting not null fields
   *//* user.setLocale("en"); -- *this is commented out, so user.locale has 
to be null, DB column default should be used *
   usersDao.insert(user);



So as you can see I do not want to set the locale. Because there is a *default 
value* defined in the DDL.

But calling this results in:

org.jooq.exception.DataAccessException: SQL [insert into "public"."users" 
("account_id", "email", "username", "locale", "time_zone", "first_name", 
"last_name", "company_name", "deactivated_at", "created_at", "updated_at", 
"encrypted_password", "reset_password_token", "reset_password_sent_at", 
"remember_created_at", "sign_in_count", "current_sign_in_at", 
"last_sign_in_at", "current_sign_in_ip", "last_sign_in_ip", 
"authentication_token", "confirmation_token", "confirmed_at", 
"confirmation_sent_at", "unconfirmed_email", "failed_attempts", 
"unlock_token", "locked_at", "avatar", "uuid", "avatar_updated_at", 
"avatar_crop_w", "avatar_crop_h", "avatar_crop_x", "avatar_crop_y", 
"signed_up_as", "welcome_wizard_hide", "list_newsletter", "referring_url", 
"landing_url") values (?, ?, ?, ?, ?, ?, ?, ?, cast(? as timestamp), cast(? 
as timestamp), cast(? as timestamp), ?, ?, cast(? as timestamp), cast(? as 
timestamp), ?, cast(? as timestamp), cast(? as timestamp), ?, ?, ?, ?, 
cast(? as timestamp), cast(? as timestamp), ?, ?, ?, cast(? as timestamp), 
?, ?, cast(? as timestamp), ?, ?, ?, ?, ?, ?, ?, ?, ?) returning 
"public"."users"."id"]; ERROR: *null value in column "locale" violates 
not-null constraint*
at org.jooq.impl.Utils.translate(Utils.java:1211)


As it seems to me, jooq forces the "null" value for the insert. So the DB 
has no chance to use the default value.


   - Is that a wished behavior?
   - Or am I doing something wrong?










-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to