Quarkus Hibernate Reactive panache mysql



我正试图用Reactive jackson hibernate panache mysql作为DB构建一个小型应用程序。

我得到以下错误。

"stackTrace":"java.lang.IollegalStateException:没有池为持久性单元定义默认响应io.quarkus.hibernate reactive.runtime.FastBootHibernate ReactivePersistenceProvider.registerVertxAndPool(FastBootHibernate reactivePersistence Provider.java:233(\n\tatio.quarkus.hibernate reactive.runtime.FastBootHibernate ReactivePersistenceProvider.rewireMetadataAndExtractServiceRegistry(FastBootHibernate reactivePersistence Provider.java:180(\n\tatio.quarkus.hibernate reactive.runtime.FastBootHibernate ReactivePersistenceProvider.getEntityManagerFactoryBuilderOrNull(FastBootHibernate reactivePersistence Provider.java:156(\n\tatio.quarkus.hibernate reactive.runtime.FastBootHibernate ReactivePersistenceProvider.createEntityManagerFactory(FastBootHibernate reactivePersistence Provider.java:82(\n\tatjavax.persistence.persistence.createEntityManagerFactory(persistence.java:80(\n\tatjavax.persistence.persistence.createEntityManagerFactory(persistence.java:55(\n\tatio.quarkus.hibernate.orm.runtime.JPAConfig$LazyPersistenceUnit.get(JPAConfig.java:118(\n\tatio.quarkus.hibernate.orm.runtime.JPAConfig.startAll(JPAConfig.java:42(\n\tatio.quarkus.hibernate.orm.runtime.JPAConfig_Subclass.startAll$$superaccessor5(JPAConfig_subclasszig:769(\n\tatio.quarkus.hibernate.orm.runtime.JPAConfig_Subclass$$函数$$5.apply(JPAConfig_Subclass$$函数$$5.zig:29(\n\tatio.quarkus.arc.impl.AroundInvokeInvocationContext.pround(AroundInvokeInvocation Context.java:54(\n\tatio.quarkus.arc.runtime.devconsole.InvocationInterceptor.prough(InvocationInterceptor.java:62(\n\tatio.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:51(\n\tatio.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.entercept(InvocationInterceptor_beanzig:521(\n\tatio.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvoation.java:41(\n\tatio.quarkus.arc.impl.AroundInvokeInvocationContext.coperform(AroundInvokeInvocation Context.java:41(\n\tatio.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32(\n\tatio.quarkus.hibernate.orm.runtime.JPAConfig_Subclass.startAll(JPAConfig_subclasszig:727(\n\tatio.quarkus.hibernate.orm.runtime.Hhibernate OrmRecorder.startAllPersistenceUnits(hibernate OrmLogger.java:88(\n\tatio.quarkus.deployment.steps.HHibernate OrmProcessor$startPersistenceUnits951856026.deploy_0io.quarkus.deployment.steps.HHibernate OrmProcessor$startPersistenceUnits951856026.deploy(Hibernate OrmProcessor$startPersstenceUnits951856026.zig:40(\n\tatio.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:751(\n\tatio.quarkus.runtime.Application.start(Application.java:90(\n\tatio.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleMnager.java:100(\n\tatio.quarkus.runtime.quarkus.run(quarkus.java:66(\n\tatio.quarkus.runtime.quarkus.run(quarkus.java:42(\n\tatio.quarkus.runtime.quarkus.run(quarkus.java:119(\n\tatio.quarkus.runner.GeneratedMain.main(GeneratedMainzig:29(\n\tatjava.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native方法(\n\tatjava.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78(\n\tatjava.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43(\n\tatjava.base/java.lang.reflect.Method.ioke(Method.java:567(\n\tatio.quarkus.runner.bbootstrap.StartupActionImpl$3.run(StartupActionImpl.java:134(\n\tatjava.base/java.lang.Thread.run(线程.java:831(\n">

知道缺少什么吗?。

我有型号

@Entity
public class Nation extends PanacheEntity {
@Column
public String country;
public Nation(String country, List<State> states) {
this.country = country;
this.states = states;
}
@OneToMany(cascade = {CascadeType.ALL})
public List<State> states = new ArrayList<>();
public Nation() {
}
}
@Entity
public class State extends PanacheEntity {
public State(String state, List<District> districts) {
this.state = state;
this.districts = districts;
}
@Column
public String state;
@OneToMany
public List<District> districts = new ArrayList<>();
public State() {
}
}

@Entity
public class District extends PanacheEntity {
public District(String district, List<Village> villages) {
this.district = district;
this.villages = villages;
}
@Column
public String district;
@OneToMany
public List<Village> villages = new ArrayList<>();
public District() {
}
}

@Entity
public class Village extends PanacheEntity {
@Column
public String village;
public Village(String village) {
this.village = village;
}
public Village() {
}
}

@Path("/nation")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApplicationScoped
public class NationResource {
@Inject
NationRepository nationRepository;
/* @Inject
public NationResource(NationRepository nationRepository) {
this.nationRepository = nationRepository;
}*/
@POST
@Path("save")
public Uni<Void> saveNation(Nation nation) {
return nationRepository.persist(nation);
}
@GET
public Uni<List<Nation>> getNations() {
return nationRepository.listAll();
}
@GET
@Path("{id}")
public Uni<Nation> getNation(@PathParam("id") Long id) {
return nationRepository.findById(id);
}
}

quarkus:
http:
port: 4754
log:
console:
json:
pretty-print: true
date-format: "YYYY-MM-dd HH:mm:ss"
exception-output-type: "detailed-and-formatted"
# configure your datasource
datasource:
db-kind: mysql
username: root
password: root
reactive:
url: vertx-reactive:mysql://localhost:3306/garrsolutions
# drop and create the database at startup (use `update` to only update the schema)
hibernate-orm:
database:
generation: drop-and-create

我通过在pom.xml依赖项中添加以下snip来解决这个问题:

<!-- JDBC driver dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-pg-client</artifactId>
</dependency>

在我的例子中,我试图使用H2-Db,但我遇到了同样的问题。我使用基于地图的方法解决了这个问题,例如:

发件人:

quarkus.datasource.db-kind=h2 
quarkus.datasource.jdbc.url=jdbc:h2:mem:guitars
quarkus.hibernate-orm.database.generation=drop-and-create 
quarkus.hibernate-orm.packages=package br.com.mp.product.models

收件人:

quarkus.datasource."guitars".db-kind=h2
quarkus.datasource."guitars".jdbc.url=jdbc:h2:mem:guitars
quarkus.hibernate-orm."guitars".database.generation=drop-and-create 
quarkus.hibernate-orm."guitars".packages=package br.com.mp.product.models

通过这种方式,hibernate可以从映射中找到指定的类,但我没有尝试像您的情况那样使用MySql Db。

我在这个链接中看到了这个例子:https://quarkus.io/guides/hibernate-orm

相关内容

  • 没有找到相关文章

最新更新