休眠中的 Quarkus 构建失败:定义了多个持久性单元,但实体未映射到它们
Quarkus build failure in hibernate: Multiple persistence units are defined but the entities are not mapped to them
我似乎无法让我的 Postgresql 数据库与 quarkus 和 hibernate 一起工作。没有我遇到的错误示例:
java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[error]: Build step io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor#configurationDescriptorBuilding threw an exception: io.quarkus.runtime.configuration.ConfigurationException: Multiple persistence units are defined but the entities are not mapped to them. You should either use the .packages Quarkus configuration property or package-level @PersistenceUnit annotations.
这是我的 application.properties:
#Connector database
quarkus.datasource.conn.db-kind=pg
quarkus.datasource.conn.jdbc.url=quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/testdb
quarkus.datasource.conn.username=postgresql
quarkus.datasource.conn.password=password
quarkus.hibernate-orm.conn.datasource=conn
我正在尝试像这样在我的 class 中绑定它:
@ApplicationScoped
public class Service {
@Inject
@PersistenceContext(unitName = "conn")
protected EntityManager eventEM;
...
尝试将它与@PersistenceUnit(...) 绑定也不起作用。
我尝试绑定多个实体,如下所示:
@Entity
@Table(name = "name")
@NoArgsConstructor
@Getter
@EqualsAndHashCode
@ToString
public class MyEntity {
@Id
@Column(name = "id", updatable = false)
private String id;
...
如果没有 persistence.xml,这不应该工作吗?
非常感谢! :)
您需要将实体包附加到持久性单元。
有两种方法可以将模型 类 附加到持久性单元,它们不能混用:
通过包配置属性(例如quarkus.hibernate-orm.conn.packages=your.package);
通过@io.quarkus.hibernate.orm.PersistenceUnit 包级注解。
更多信息请阅读https://quarkus.io/guides/hibernate-orm#multiple-persistence-units
我似乎无法让我的 Postgresql 数据库与 quarkus 和 hibernate 一起工作。没有我遇到的错误示例:
java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[error]: Build step io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor#configurationDescriptorBuilding threw an exception: io.quarkus.runtime.configuration.ConfigurationException: Multiple persistence units are defined but the entities are not mapped to them. You should either use the .packages Quarkus configuration property or package-level @PersistenceUnit annotations.
这是我的 application.properties:
#Connector database
quarkus.datasource.conn.db-kind=pg
quarkus.datasource.conn.jdbc.url=quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/testdb
quarkus.datasource.conn.username=postgresql
quarkus.datasource.conn.password=password
quarkus.hibernate-orm.conn.datasource=conn
我正在尝试像这样在我的 class 中绑定它:
@ApplicationScoped
public class Service {
@Inject
@PersistenceContext(unitName = "conn")
protected EntityManager eventEM;
...
尝试将它与@PersistenceUnit(...) 绑定也不起作用。
我尝试绑定多个实体,如下所示:
@Entity
@Table(name = "name")
@NoArgsConstructor
@Getter
@EqualsAndHashCode
@ToString
public class MyEntity {
@Id
@Column(name = "id", updatable = false)
private String id;
...
如果没有 persistence.xml,这不应该工作吗?
非常感谢! :)
您需要将实体包附加到持久性单元。
有两种方法可以将模型 类 附加到持久性单元,它们不能混用:
通过包配置属性(例如quarkus.hibernate-orm.conn.packages=your.package);
通过@io.quarkus.hibernate.orm.PersistenceUnit 包级注解。
更多信息请阅读https://quarkus.io/guides/hibernate-orm#multiple-persistence-units