lundi 6 juillet 2015

Insert Returning Query For MySQL in JOOQ

am trying to use the following code to get the auto generated id . My back end is MySQL. Code looks like this

Record record = create.insertInto(CANDIDATE, CANDIDATE.FIRST_NAME,      
       CANDIDATE.LAST_NAME,CANDIDATE.EXTRACTED_NAME)
       .values("Charlotte", "Roche","Charlotte Roche")
       .returning(CANDIDATE.ID)
       .fetchOne();

System.out.println(record.getValue(CANDIDATE.ID));

I am getting NullPointerException. I took a look at http://ift.tt/1KIXgjG . It says

Derby, H2, Ingres, MySQL, SQL Server only allow for retrieving IDENTITY column values as "generated key". If other fields are requested, a second statement is issued. Client code must assure transactional integrity between the two statements.

As per my understanding in Mysql auto_increment works as IDENTITY. Can anybody please throw some light on how to achieve this for MySQL

I have taken a look at this SO Question on a similar topic and tried following

Result<?>  record =
            create.insertInto(CANDIDATE, CANDIDATE.FIRST_NAME, CANDIDATE.LAST_NAME,CANDIDATE.EXTRACTED_NAME)
                  .values("Charlotte", "Roche","Charlotte Roche")
                  .returning(CANDIDATE.ID)
                  .fetch();

            System.out.println(record.size());

Though it inserts record in the backend but it prints the record.size() as zero

Aucun commentaire:

Enregistrer un commentaire