Description
openedon Jul 11, 2023
Description
Hello everyone,
I came across an unsupported feature in the "quarkus-spring-data-jpa" extension which is often very usefull or quite mandatory and therefore an addition to the already fixed bug at: #10870
The problem is regarding on how one can implement composit primary keys in hibernate orm. As the documentations of Hibernate shows (here) there are two ways to implement composite primary keys in hibernate:
- javax.persistence.EmbeddedId (or jakarta.persistence.EmbeddedId)
- javax.persistence.IdClass (or jakarta.persistence.IdClass)
There are of course many differenced between those two ways but the one I want to highlight is that it is only possible to use the @GeneratedValue annotation on the compositekey class when using the @IdClass variant (see).
So whats the problem with the quarkus extension?
In quarkus only the @EmbeddedId annotation is supported for composite primary keys. Therefore it's impossible to use eg. the @GeneratedValue annotation on a part of a composite primary key.
If you dare to try it this fancy error occurs:
2023-06-12 13:53:15,117 ERROR [io.qua.dep.dev.IsolatedDevModeMain] (main) Failed to start quarkus: java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[error]: Build step io.quarkus.spring.data.deployment.SpringDataJPAProcessor#build threw an exception: java.lang.IllegalArgumentException: Currently the @Id or @EmbeddedId annotation can only be placed on a single field or method. Offending class is my.hibernate.Class
at io.quarkus.spring.data.deployment.generate.StockMethodsAdder.getIdAnnotationTargetRec(StockMethodsAdder.java:1063)
at io.quarkus.spring.data.deployment.generate.StockMethodsAdder.getIdAnnotationTarget(StockMethodsAdder.java:1039)
at io.quarkus.spring.data.deployment.generate.StockMethodsAdder.generateSave(StockMethodsAdder.java:149)
at io.quarkus.spring.data.deployment.generate.StockMethodsAdder.add(StockMethodsAdder.java:89)
at io.quarkus.spring.data.deployment.generate.SpringDataRepositoryCreator.implementCrudRepository(SpringDataRepositoryCreator.java:115)
at io.quarkus.spring.data.deployment.SpringDataJPAProcessor.implementCrudRepositories(SpringDataJPAProcessor.java:264)
at io.quarkus.spring.data.deployment.SpringDataJPAProcessor.build(SpringDataJPAProcessor.java:129)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:909)
at io.quarkus.builder.BuildContext.run(BuildContext.java:282)
at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
at java.base/java.lang.Thread.run(Thread.java:834)
at org.jboss.threads.JBossThread.run(JBossThread.java:501)
I think there are quite a lot users who would benefit from this feature as there are some related questions online eg.https://stackoverflow.com/questions/61211391/are-composite-primary-keys-in-jpa-with-quarkus-possible
Let me know if anything is unclear..
Thanks
Implementation ideas
No response