如何设置quarkus spring hibernate和multitenant?

hkmswyz6  于 2021-07-23  发布在  Java
关注(0)|答案(1)|浏览(635)

早上好,我正在尝试用spring、hibernate和multitenant设置quarkus项目。但不在运行查询时更改模式?如何设置配置,以便查询在正确的预期模式上动态运行?
应用程序.yml

  1. quarkus:
  2. datasource:
  3. db-kind: postgres
  4. username: postgres
  5. password: 1234
  6. jdbc:
  7. url: jdbc:postgresql://localhost:5432/postgres
  8. driver: org.postgresql.Driver
  9. hibernate-orm:
  10. multitenant: SCHEMA
  11. dialect: org.hibernate.dialect.PostgreSQLDialect
  12. log:
  13. sql: true

租户解析程序

  1. package br.com.rhino.config;
  2. import java.util.Optional;
  3. import io.quarkus.hibernate.orm.runtime.tenant.TenantResolver;
  4. import io.vertx.ext.web.RoutingContext;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Component;
  7. @Component
  8. public class CustomTenantResolver implements TenantResolver {
  9. public static String DEFAULT_TENANT = "rhino";
  10. @Autowired
  11. RoutingContext context;
  12. @Override
  13. public String getDefaultTenantId() {
  14. return DEFAULT_TENANT;
  15. }
  16. @Override
  17. public String resolveTenantId() {
  18. return Optional.ofNullable(context.request().getHeader("x-tenantId")).orElse(DEFAULT_TENANT);
  19. }
  20. }

正确截距
调试映像中的正确租户返回
日志

  1. --/ __ \/ / / / _ | / _ \/ //_/ / / / __/
  2. -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \
  3. --\___\_\____/_/ |_/_/|_/_/|_|\____/___/
  4. 2021-03-09 08:02:15,282 INFO [io.qua.fly.FlywayProcessor] (build-20) Adding application migrations in path '/home/idd_acosta/freelas/rhino/rhino-api/target/classes/db/migration/maripa/' using protocol 'file'
  5. 2021-03-09 08:02:15,669 INFO [io.qua.arc.pro.BeanProcessor] (build-24) Found unrecommended usage of private members (use package-private instead) in application beans:
  6. - @Inject field br.com.rhino.user.mapper.UserMapperImpl#roleMapper,
  7. - @Inject field br.com.rhino.user.mapper.RoleMapperImpl#permissionMapper
  8. 2021-03-09 08:02:16,591 INFO [org.fly.cor.int.lic.VersionPrinter] (Quarkus Main Thread) Flyway Community Edition 7.5.2 by Redgate
  9. 2021-03-09 08:02:16,670 INFO [org.fly.cor.int.dat.bas.DatabaseType] (Quarkus Main Thread) Database: jdbc:postgresql://localhost:5432/postgres (PostgreSQL 13.1)
  10. 2021-03-09 08:02:16,686 INFO [org.fly.cor.int.com.DbClean] (Quarkus Main Thread) Successfully dropped pre-schema database level objects (execution time 00:00.000s)
  11. 2021-03-09 08:02:16,709 INFO [org.fly.cor.int.com.DbClean] (Quarkus Main Thread) Successfully dropped schema "maripa" (execution time 00:00.021s)
  12. 2021-03-09 08:02:16,710 INFO [org.fly.cor.int.com.DbClean] (Quarkus Main Thread) Successfully dropped schema " bicas" (execution time 00:00.001s)
  13. 2021-03-09 08:02:16,712 INFO [org.fly.cor.int.com.DbClean] (Quarkus Main Thread) Successfully dropped schema " rhino" (execution time 00:00.001s)
  14. 2021-03-09 08:02:16,712 INFO [org.fly.cor.int.com.DbClean] (Quarkus Main Thread) Successfully dropped post-schema database level objects (execution time 00:00.000s)
  15. 2021-03-09 08:02:16,714 INFO [org.fly.cor.int.lic.VersionPrinter] (Quarkus Main Thread) Flyway Community Edition 7.5.2 by Redgate
  16. 2021-03-09 08:02:16,718 INFO [org.fly.cor.int.dat.bas.Schema] (Quarkus Main Thread) Creating schema "maripa" ...
  17. 2021-03-09 08:02:16,718 INFO [org.fly.cor.int.dat.bas.Schema] (Quarkus Main Thread) Creating schema " bicas" ...
  18. 2021-03-09 08:02:16,719 INFO [org.fly.cor.int.dat.bas.Schema] (Quarkus Main Thread) Creating schema " rhino" ...
  19. 2021-03-09 08:02:16,721 INFO [org.fly.cor.int.sch.JdbcTableSchemaHistory] (Quarkus Main Thread) Creating Schema History table "maripa"."flyway_schema_history" ...
  20. 2021-03-09 08:02:16,755 INFO [org.fly.cor.int.com.DbMigrate] (Quarkus Main Thread) Current version of schema "maripa": null
  21. 2021-03-09 08:02:16,762 INFO [org.fly.cor.int.com.DbMigrate] (Quarkus Main Thread) Migrating schema "maripa" to version "1.0.1 - start structure maripa"
  22. 2021-03-09 08:02:16,813 INFO [org.fly.cor.int.com.DbMigrate] (Quarkus Main Thread) Successfully applied 1 migration to schema "maripa" (execution time 00:00.066s)
  23. 2021-03-09 08:02:17,120 INFO [io.qua.sch.run.SimpleScheduler] (Quarkus Main Thread) No scheduled business methods found - Simple scheduler will not be started
  24. 2021-03-09 08:02:17,194 INFO [io.quarkus] (Quarkus Main Thread) rhino-api 1.0.0-SNAPSHOT on JVM (powered by Quarkus 1.12.1.Final) started in 2.714s. Listening on: http://localhost:8080
  25. 2021-03-09 08:02:17,194 INFO [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated.
  26. 2021-03-09 08:02:17,194 INFO [io.quarkus] (Quarkus Main Thread) Installed features: [agroal, cdi, config-yaml, flyway, hibernate-orm, hibernate-orm-panache, hibernate-orm-rest-data-panache, jdbc-postgresql, micrometer, mutiny, narayana-jta, resteasy, resteasy-jackson, scheduler, security, smallrye-context-propagation, spring-data-jpa, spring-di, spring-scheduled, spring-security, spring-web]
  27. Hibernate:
  28. select
  29. user0_.id as id1_7_,
  30. user0_.dt_creation as dt_creat2_7_,
  31. user0_.email as email3_7_,
  32. user0_.password as password4_7_,
  33. user0_.dt_update as dt_updat5_7_,
  34. user0_.username as username6_7_
  35. from
  36. user user0_
  37. 2021-03-09 08:09:33,430 WARN [org.hib.eng.jdb.spi.SqlExceptionHelper] (executor-thread-1) SQL Error: 0, SQLState: 42703
  38. 2021-03-09 08:09:33,430 ERROR [org.hib.eng.jdb.spi.SqlExceptionHelper] (executor-thread-1) ERROR: column user0_.id does not exist
  39. Posição: 8
  40. 2021-03-09 08:09:33,441 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (executor-thread-1) HTTP Request to /user failed, error id: 0866564b-c6ab-43be-b245-ab70add72f26-1: org.jboss.resteasy.spi.UnhandledException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
  41. at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:106)
  42. at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:372)
  43. at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:218)
  44. at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:519)
  45. at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:261)
  46. at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:161)
  47. at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
  48. at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:164)
  49. at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:247)
  50. at io.quarkus.resteasy.runtime.standalone.RequestDispatcher.service(RequestDispatcher.java:73)
  51. at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.dispatch(VertxRequestHandler.java:138)
  52. at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.access$000(VertxRequestHandler.java:41)
  53. at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler$1.run(VertxRequestHandler.java:93)
  54. at io.quarkus.runtime.CleanableExecutor$CleaningRunnable.run(CleanableExecutor.java:231)
  55. at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
  56. at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
  57. at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2415)
  58. at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
  59. at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
  60. at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
  61. at java.base/java.lang.Thread.run(Thread.java:834)
  62. at org.jboss.threads.JBossThread.run(JBossThread.java:501)
  63. Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
  64. at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154)
  65. at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1602)
  66. at org.hibernate.query.Query.getResultList(Query.java:165)
  67. at io.quarkus.hibernate.orm.panache.common.runtime.CommonPanacheQueryImpl.list(CommonPanacheQueryImpl.java:230)
  68. at io.quarkus.hibernate.orm.panache.runtime.PanacheQueryImpl.list(PanacheQueryImpl.java:149)
  69. at br.com.rhino.user.service.UserService.findAllUsers(UserService.java:73)
  70. at br.com.rhino.user.controller.UserController.findAll(UserController.java:36)
  71. at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  72. at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  73. at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  74. at java.base/java.lang.reflect.Method.invoke(Method.java:566)
  75. at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:170)
  76. at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:130)
  77. at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:643)
  78. at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:507)
  79. at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$2(ResourceMethodInvoker.java:457)
  80. at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
  81. at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:459)
  82. at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:419)
  83. at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:393)
  84. at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:68)
  85. at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:492)
  86. ... 18 more
  87. Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
  88. at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:103)
  89. at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
  90. at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
  91. at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
  92. at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:67)
  93. at org.hibernate.loader.Loader.getResultSet(Loader.java:2303)
  94. at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2056)
  95. at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2018)
  96. at org.hibernate.loader.Loader.doQuery(Loader.java:948)
  97. at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:349)
  98. at org.hibernate.loader.Loader.doList(Loader.java:2849)
  99. at org.hibernate.loader.Loader.doList(Loader.java:2831)
  100. at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2663)
  101. at org.hibernate.loader.Loader.list(Loader.java:2658)
  102. at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:506)
  103. at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:400)
  104. at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:219)
  105. at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1414)
  106. at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1625)
  107. at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1593)
  108. ... 38 more
  109. Caused by: org.postgresql.util.PSQLException: ERROR: column user0_.id does not exist
  110. Posição: 8
  111. at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2553)
  112. at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2285)
  113. at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:323)
  114. at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:473)
  115. at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:393)
  116. at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:164)
  117. at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:114)
  118. at io.agroal.pool.wrapper.PreparedStatementWrapper.executeQuery(PreparedStatementWrapper.java:76)
  119. at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:57)
  120. ... 53 more

旁白:对不起我的英语!:)

nwwlzxa7

nwwlzxa71#

不确定应用程序代码的外观,但您似乎遵循以下文档:https://quarkus.io/guides/hibernate-orm#multitenancy
如果您的实体没有指定显式模式,我建议您使用复制器创建错误报告:https://github.com/quarkusio/quarkus/issues/new?assignees=&labels=kind%2fbug&template=bug_report.md&title=

相关问题