Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposed Entitys dont support "Composite Primary Key" #1533

Open
TureBentzin opened this issue Jun 16, 2022 · 4 comments
Open

Exposed Entitys dont support "Composite Primary Key" #1533

TureBentzin opened this issue Jun 16, 2022 · 4 comments
Assignees

Comments

@TureBentzin
Copy link

TureBentzin commented Jun 16, 2022

I'm not a convenient user of Kotlin and I'm more the java dude.
But I started using Exposed for my new project and encountered an issue. While planning my project (and my databases) I thought I could use (as I know them from SQL) Composite Primary Keys so I can (for example) save for a value each day a specific value.
While coding the project I wrote for each table an Entity (DAO) so I could use them easily without dealing with SQL or expressions for selecting and inserting into the database. When I tried to build a table with a Composite Primary Key, I found that there seems no way to use (DAO). This would be a great addition to Exposed I think.

Greeting from Germany

That is the table I want to create a Entity for:

object DbExampleTable : Table("example") {
    val uuid = uuid("uuid")                    //Key
    val char = varchar("char",255)           //Key
    val data = byte("data")

    override val primaryKey = PrimaryKey(arrayOf(uuid, char),"pk_$tableName")
}
@bog-walk bog-walk self-assigned this Dec 8, 2023
@wissil
Copy link

wissil commented May 5, 2024

Hello, would like to double check if there's any updates on this issue or any recommended workarounds from the team?

In the previous versions I was able to use composite PKs like this:

object CarHasWheelsTable : Table(name = "car_has_wheels") {
    val carId = reference(name = "car_id", foreign = CarTable)
    val wheelId = reference(name = "wheel_id", foreign = WheelTable)

    override val primaryKey = PrimaryKey(carId, wheelId)
}

But with Exposed 50.0, the following exception is thrown:

... CarHasWheelsTable cannot be cast to class org.jetbrains.exposed.dao.id.IdTable

I see that @bog-walk has self-assigned this issue, which makes me think this being worked on? However, it would be great to get some guidance on how to deal with cases like that in the current version of Exposed. Thank you!

@bog-walk
Copy link
Member

bog-walk commented May 6, 2024

Hi @wissil Yes, the composite PK feature is currently in progress and we are reviewing potential designs. Here's the YouTrack issue EXPOSED-77 to track if you're interested.

Based on your example, the exception you're seeing is most likely due to a bug from the recent type safety changes. This was already caught and fixed in PR #2074 (EXPOSED-371).
As mentioned in the link, if this exception is in fact being thrown during column value setting (inserts/updates), the workaround until the fix is released would be to set the column value as an EntityID(carId_value, CarTable).

If this doesn't work or you don't believe that the linked issue is related to your use case, please consider opening a new issue on YouTrack with more details so we can investigate further.

mnonnenmacher pushed a commit to eclipse-apoapsis/ort-server that referenced this issue May 6, 2024
ORT has upgraded to Exposed 0.50.0 which has a bug [1] that prevents
using it in the server. Fix the Exposed version to 0.49.0 until the
fix [2] has been released.

[1]: JetBrains/Exposed#1533 (comment)
[2]: JetBrains/Exposed#2074
github-merge-queue bot pushed a commit to eclipse-apoapsis/ort-server that referenced this issue May 6, 2024
ORT has upgraded to Exposed 0.50.0 which has a bug [1] that prevents
using it in the server. Fix the Exposed version to 0.49.0 until the
fix [2] has been released.

[1]: JetBrains/Exposed#1533 (comment)
[2]: JetBrains/Exposed#2074
@wissil
Copy link

wissil commented May 7, 2024

Based on your example, the exception you're seeing is most likely due to a bug from the recent type safety changes. This was already caught and fixed in PR #2074 (EXPOSED-371).

Hi, thank you!

Yes, that indeed looks like it is going to fix the issue we have. I'll wait for when this is released and try it out.

@bog-walk
Copy link
Member

bog-walk commented May 9, 2024

@wissil Version 0.50.1 has been released with the mentioned fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants