Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jooq how to query entity based on composite key

How to query an entity based on a composite key in Jooq? E.g.:

UserAttempts org.jooq.impl.DAOImpl.findById(Record2<UInteger, String> id)

id is a composite key. How to use the Record2<UInteger, String>?

like image 996
ChunfyTseng Avatar asked Jan 27 '17 06:01

ChunfyTseng


People also ask

How do I write a SQL query for composite primary key?

CREATE TABLE COMPO ( EMP_ID INT, DEPT_ID INT, EMPNAME VARCHAR(25), GENDER VARCHAR(6), SALARY INT --> //This statement will create a //composite Primary Key from PRIMARY KEY (EMP_ID,DEPT_ID) with the help of Column EMP_ID and DEPT_ID );

How do I find the composite key in SQL?

You can use aggregate function count(*). If it returns a value greater than 1, that would mean the table has composite primary key.

Can key attributes be composite?

Composite Keys: Sometimes it requires more than one attribute to uniquely identify an entity. A primary key that made up of more than one attribute is known as a composite key. Below shows an example of a composite key.

What is the difference between the main key and a composite key give instances of how primary key and composite are used?

While a primary key and a composite key might do the same things, the primary key will consist of one column, where the composite key will consist of two or more columns. The relationship between a primary key and a foreign key is quite different.


1 Answers

You can construct a Record2 using DSLContext.newRecord():

UserAttempts attempts =
dao.findById(ctx.newRecord(USER_ATTEMPTS.ID_COLUMN1, USER_ATTEMPTS.ID_COLUMN2)
                .values(uint(1), "abc"));
like image 128
Lukas Eder Avatar answered Sep 29 '22 14:09

Lukas Eder