quarkus
quarkus copied to clipboard
jakarta data @save method result in no bean found
Describe the bug
in an attempt to make a simple example of. using Jakarta Data with no entities I had this snag:
Given:
@Repository
interface PersonRepository {
@SQL("SELECT * FROM Person WHERE name = :name")
List<Person> findByName(String name);
}
and
package org.acme;
public class Person {
public Long id;
public String name;
public String email;
public String phone;
public String address;
public String city;
public String state;
public Person() {
}
public Person(Long id, String name, String email, String phone, String address, String city, String state) {
this.id = id;
this.name = name;
this.email = email;
this.phone = phone;
this.address = address;
this.city = city;
this.state = state;
}
@Override
public String toString() {
return "Person{" +
"id=" + id +
", name='" + name + '\'' +
", email='" + email + '\'' +
", phone='" + phone + '\'' +
'}';
}
}
using
@ApplicationScoped
public class Main {
@Inject
PersonRepository personRepository;
@Transactional
void onStart(@Observes StartupEvent event) {
var persons = personRepository.findByName("Max");
Log.info("People: " + persons);
}
}
everything is fine.
but if i add @save:
@Repository
interface PersonRepository {
@SQL("SELECT * FROM Person WHERE name = :name")
List<Person> findByName(String name);
@Save
void save(Person person);
}
I get:
[ERROR] Failed to execute goal io.quarkus.platform:quarkus-maven-plugin:3.21.4:build (default) on project hey-data: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[ERROR] [error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: jakarta.enterprise.inject.spi.DeploymentException: jakarta.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type org.acme.PersonRepository and qualifiers [@Default]
[ERROR] - injection target: org.acme.Main#personRepository
[ERROR] - declared on CLASS bean [types=[org.acme.Main, java.lang.Object], qualifiers=[@Default, @Any], target=org.acme.Main]
[ERROR] at io.quarkus.arc.processor.BeanDeployment.processErrors(BeanDeployment.java:1581)
[ERROR] at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:338)
[ERROR] at io.quarkus.arc.processor.BeanProcessor.initialize(BeanProcessor.java:178)
[ERROR] at io.quarkus.arc.deployment.ArcProcessor.validate(ArcProcessor.java:489)
[ERROR] at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:733)
[ERROR] at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:856)
[ERROR] at io.quarkus.builder.BuildContext.run(BuildContext.java:255)
[ERROR] at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
[ERROR] at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2675)
[ERROR] at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2654)
[ERROR] at org.jboss.threads.EnhancedQueueExecutor.runThreadBody(EnhancedQueueExecutor.java:1627)
[ERROR] at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1594)
[ERROR] at java.base/java.lang.Thread.run(Thread.java:1583)
[ERROR] at org.jboss.threads.JBossThread.run(JBossThread.java:499)
[ERROR] Caused by: jakarta.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type org.acme.PersonRepository and qualifiers [@Default]
[ERROR] - injection target: org.acme.Main#personRepository
[ERROR] - declared on CLASS bean [types=[org.acme.Main, java.lang.Object], qualifiers=[@Default, @Any], target=org.acme.Main]
[ERROR] at io.quarkus.arc.processor.Beans.resolveInjectionPoint(Beans.java:547)
[ERROR] at io.quarkus.arc.processor.BeanInfo.init(BeanInfo.java:689)
[ERROR] at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:323)
[ERROR] ... 12 more
[ERROR] -> [Help 1]
I reckon there is some missing requirement of identifying @Id and some annotation processor or generator is failing but shouldn't that show up at build time?
Expected behavior
warn/error about why @Save annotation breaks things
Actual behavior
No response
How to Reproduce?
Output of uname -a or ver
No response
Output of java -version
No response
Quarkus version or git rev
No response
Build tool (ie. output of mvnw --version or gradlew --version)
No response
Additional information
| Key | Value |
|---|---|
| uname -a | Darwin manderse-mac 24.4.0 Darwin Kernel Version 24.4.0: Wed Mar 19 21:16:34 PDT 2025; root:xnu-11417.101.15~1/RELEASE_ARM64_T6000 arm64 |
| java -version | openjdk version "21.0.6" 2025-01-21 LTS OpenJDK Runtime Environment Temurin-21.0.6+7 (build 21.0.6+7-LTS) OpenJDK 64-Bit Server VM Temurin-21.0.6+7 (build 21.0.6+7-LTS, mixed mode, sharing) |
| mvnw --version | Apache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d260186937) Maven home: /Users/manderse/.m2/wrapper/dists/apache-maven-3.9.9-bin/33b4b2b4/apache-maven-3.9.9 Java version: 21.0.6, vendor: Eclipse Adoptium, runtime: /Users/manderse/.jbang/cache/jdks/21 Default locale: en_DK, platform encoding: UTF-8 OS name: "mac os x", version: "15.4", arch: "aarch64", family: "mac" |
| quarkus.platform.artifact-id | quarkus-bom |
| quarkus.platform.group-id | io.quarkus.platform |
| quarkus.platform.version | 3.21.4 |
/cc @quarkusio/devtools (jbang)
Worth noting that many fixes were done on 7.x version of Hibernate processor (isn't jpamodelgen anymore). I don't think they were also done in 6.x branch.
cc @FroMage
Looks like you're missing @Entity on your entity :)
This might be a bug in the ORM processor, or as @cvgaviao said, already fixed upstream in 7…
With your code I'm getting these errors even without @Save added:
2025-04-29 16:01:33,746 WARN [io.qua.hib.orm.dep.HibernateOrmProcessor] (build-40) Hibernate ORM is disabled because no JPA entities were found
[error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: jakarta.enterprise.inject.spi.DeploymentException: jakarta.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type org.hibernate.StatelessSession and qualifiers [@Default]
- injection target: parameter 'session' of org.acme.PersonRepository_ constructor
- declared on CLASS bean [types=[org.acme.PersonRepository_, org.acme.PersonRepository, java.lang.Object], qualifiers=[@Default, @Any], target=org.acme.PersonRepository_]
So the PersonRepository_ class is properly created, but we're not getting any session due to lack of any entity.
If I add @Entity I do get an exception complaining about the lack of @Id:
Caused by: org.hibernate.AnnotationException: Entity 'org.acme.Person' has no identifier (every '@Entity' class must declare or inherit at least one '@Id' or '@EmbeddedId' property)
at org.hibernate.boot.model.internal.InheritanceState.determineDefaultAccessType(InheritanceState.java:289)
Yes, but shouldn't the processor complain about save type missing entity/if if truly required?
it would be nice not requiring @entity/@id for these - at least it seems not being required by Jakarta data to have them ?
This appears to be an ORM processor question, no? Ask upstream?
@yrodiere can you take a look at this and close if this is not a bug?
Thanks
Created https://hibernate.atlassian.net/browse/HHH-19463. Marking as an upstream bug.
@maxandersen thanks for the report, feel free to report directly to Hibernate Jira next time -- I suspect you know it well 😁
BTW I don't get notified about JBang issues, remember to label area/hibernate-orm if you want the Hibernate team to have a look.
As explained in https://hibernate.atlassian.net/browse/HHH-19463 , this is actually required by the spec: as Hibernate cannot say for sure that this repository is about Hibernate entities (no Hibernate annotations anywhere), it's supposed to ignore it to let another Jakarta Data provider (if any) handle it.
Dodgy IMO, but that's the way the spec is.
Closing.