DAO on compound/multiple primary key ?
See original GitHub issueHello,
PostgreSQL can use multiple fields as Primary Key (doc) but how to handle that with Exposed DAO ?
I tried to use the DAO with a table which is quite complexe. Because example is better than words. Here the SQL :
CREATE TABLE table__contacts_first
(
contact_id UUID NOT NULL,
app_id VARCHAR(128) NOT NULL,
--- other fields ...
FOREIGN KEY (contact_id) REFERENCES table__contacts (contact_id),
PRIMARY KEY (contact_id, app_id)
);
As you can see, the table__contacts_first
doesn’t have any PK, but the pair contact_id
+ app_id
acts as is.
I have the following Exposed Table:
object ContactsFirstTable : Table(name = "table__contacts_first") {
val contactId = reference("contact_id", ContactsTable).primaryKey()
val appId = varchar("app_id", length = 128).primaryKey()
}
And now the Exposed DAO:
class ContactFirstDao(id: EntityID<UUID>) : UUIDEntity(id) {
companion object : UUIDEntityClass<ContactFirstDao>(ContactsFirstTable)
}
Obviously, I got errors and in fact, I should construct my ContactFirstDao
using contactId
and appId
.
Do you have any idea how I could achieve that ?
Thanks 👍
Issue Analytics
- State:
- Created 3 years ago
- Reactions:23
- Comments:15 (1 by maintainers)
Top Results From Across the Web
Room @Relation with composite Primary Key - Stack Overflow
So we write a query in our Dao. @Query("select * from WorkOrder LEFT JOIN WorkOrderStaff ON woId = woIdStaff LEFT JOIN WorkOrderMachine ON...
Read more >Spring Data JPA Composite Primary Key Mapping Example
A complete guide to map a composite primary key by using both @IdClass and @EmbeddedId annotations in Spring Data JPA.
Read more >Can Multiple Primary Keys Exist on a Single Table? - Chartio
The short answer is no, a table is not allowed to contain multiple primary keys , as that goes against the fundamental principles...
Read more >Configuring Entities - CommonsWare
Composite Primary Keys ... In some cases, you may have a composite primary key, made up of two or more columns in the...
Read more >Create Composite Primary Key in VBA (DAO) - Tek-Tips
Here's where I'm stuck. I now need to set the fields CLASS / ITEM as a COMPOUND PRIMARY KEY. (I'm preparing, here, to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So, no composite keys for Exposed?
I’m not calling it ORM anymore then. Composite keys are pretty basic!
An amaizing library: SQL ! I stopped using libraries, ORMs, … Just SQL is enough. But you can take a look at Ktorm (https://ktorm.liuwj.me/).
I left that issue open because it’s an importante missing feature.