Hello,

I cannot reproduce the issue you're experiencing. Your first piece of code
yields "-> 36" on my instance, as expected. I'm using MySQL 5.5.27
with mysql-connector-java-5.1.15-bin.jar

2013/4/26 <[email protected]>

> Hey there - I'm new to JOOQ and playing around with it for possible use on
> my next project.
>
> I'm using MySQL + JOOQ 3.0.0-RC3
>
> here's a quick snippet:
>
> DSLContext create = DSL.using(this.connection, SQLDialect.MYSQL);
>>
>>
>>> GreetingRecord record = create.newRecord(GREETING);
>>
>> record.setGreetingtext("blah");
>>
>>
>>> record.store();
>>
>> System.out.println("-> " + record.getId());
>>
>>
> the ID isn't populated
>
> I've tried various permutations of this, with no luck:
>
>  create.insertInto(GREETING,
>> GREETING.GREETINGTEXT).values(greeting.getGreetingText()).returning(
>> GREETING.ID).fetch().getValues(GREETING.ID);
>>
>
> here's the DDL of the table:
>
> CREATE TABLE `greeting` (
>>
>>   `id` bigint(20) NOT NULL AUTO_INCREMENT,
>>
>>   `greetingText` text COLLATE utf8_bin NOT NULL,
>>
>>   PRIMARY KEY (`id`)
>>>
>> ) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8 COLLATE=utf8_bin$$
>>
>>
>>>
>  the inserts succeed, but I can't seem to get the generated key back; I'd
> like to use JOOQ directly and not dive down into the JDBC statement layer
>
> I think I'm just misunderstanding how to use the API - is there a direct
> way to return the ID/key MySQL auto incremented for me?
>

No, the way you're using the API is correct and is supposed to work with
MySQL. Can you execute the query using JDBC and
Statement.getGeneratedKeys() ?

i.e. what happens when you run

PreparedStatement stmt =
connection.prepareStatement(
    "insert into `greeting` ( `greetingText` ) VALUES ( 'text' )",
    Statement.RETURN_GENERATED_KEYS);

stmt.executeUpdate();
// Use jOOQ to consume the generatedKeys ResultSet
create.fetch(stmt.getGeneratedKeys());

-- 
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