My goal is to persist a list of Question POJOs to the database.
This is the Question class:
@Data
public class Question {
    private Long id;
    private String type;
    private String content;
    private String answer;
}


I'm currently using something like this in my prepared statement:
INSERT INTO Questions VALUES
(?, ?, (SELECT id FROM QuestionTypes WHERE name = ?), 
 ? FORMAT JSON, ? FORMAT JSON);


The only issue I'm facing is for the third parameter (the inner query for a 
QuestionType). In case the target type doesn't exist, the operation fails. 
What I want is: to insert a corresponding row for new QuestionType, and 
then use its id. Here's how I roughly want it to look:
INSERT INTO Questions VALUES
(?, ?, (SELECT id FROM QuestionTypes WHERE name = ?), // or 'INSERT INTO 
QuestionTypes' if absent and use the generated id
 ? FORMAT JSON, ? FORMAT JSON);


Is anything like that possible with simple commands? Would you like to 
suggest another approach?

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/h2-database/7a2265f5-ef5f-41f6-a5ea-ee19448ebdbf%40googlegroups.com.

Reply via email to