Missing store() method on a Record

426 views
Skip to first unread message

adrien....@live.fr

unread,
Dec 17, 2014, 11:09:42 AM12/17/14
to jooq...@googlegroups.com
Hi.

I took a look at that page: http://www.jooq.org/doc/3.5/manual/sql-execution/crud-with-updatablerecords/simple-crud/
I read:

// Create a new record
BookRecord book1 = create.newRecord(BOOK);

// Insert the record: INSERT INTO BOOK (TITLE) VALUES ('1984');
book1
.setTitle("1984");
book1
.store();

I generated a sample code, have that code:

import static com.example.Tables.TEST;

...

DSLContext create = DSL.using(conn, SQLDialect.POSTGRES);
TestRecord test = create.newRecord(TEST);

At that point, the test variable does not provides a store() method.
I don't understand why.

Using
create.executeInsert(back);
works.
But I'd prefer the store() way, and I see no reason for it not to be there.

My code generation does nothing strange, here is the extract of the maven configuration:

<configuration>
   
<!-- JDBC connection parameters -->
   
<jdbc>
       
<driver>org.postgresql.Driver</driver>
       
<url>jdbc:postgresql://...</url>
       
<user>...</user>
       
<password>...</password>
   
</jdbc>

   
<!-- Generator parameters -->
   
<generator>
       
<name>org.jooq.util.DefaultGenerator</name>
       
<database>
           
<name>org.jooq.util.postgres.PostgresDatabase</name>
           
<includes>.*</includes>
           
<excludes></excludes>
           
<inputSchema>public</inputSchema>
       
</database>
       
<target>
           
<packageName>...</packageName>
           
<directory>target/generated-sources/jooq</directory>
       
</target>
       
<generate>
           
<daos>true</daos>
       
</generate>
   
</generator>
</configuration>

Did I misunderstood something?


Adrien

Lukas Eder

unread,
Dec 17, 2014, 11:42:47 AM12/17/14
to jooq...@googlegroups.com
2014-12-17 17:09 GMT+01:00 <adrien....@live.fr>:

But I'd prefer the store() way, and I see no reason for it not to be there.

The reason is that UpdatableRecords can only exist in the presence of a primary key. If there is no primary key, jOOQ cannot know if a value should be updated or inserted. INSERT is always possible but UPDATE isn't...

In any case, you will probably not design your schema without primary keys, so this might not be an issue... If you do want to have updatable tables without primary keys, you can tell the code generator to produce "synthetic primary keys" as documented here:

  <!-- A regular expression matching all columns that participate in "synthetic" primary keys,
       which should be placed on generated UpdatableRecords, to be used with

        - UpdatableRecord.store()
        - UpdatableRecord.update()
        - UpdatableRecord.delete()
        - UpdatableRecord.refresh()

       Synthetic primary keys will override existing primary keys. -->
  <syntheticPrimaryKeys>SCHEMA\.TABLE\.COLUMN(1|2)</syntheticPrimaryKeys>

adrien....@live.fr

unread,
Dec 17, 2014, 11:44:56 AM12/17/14
to jooq...@googlegroups.com
I take a look at that parameter.

Thanks Lukas

Reply all
Reply to author
Forward
0 new messages