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>
?
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 );
You can use aggregate function count(*). If it returns a value greater than 1, that would mean the table has composite primary key.
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.
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.
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"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With