我似乎無法讓我的 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
我正在嘗試將它系結在我的班級中,如下所示:
@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,這不應該作業嗎?
真的很感激!:)
uj5u.com熱心網友回復:
您需要將物體包附加到持久性單元。
將模型類附加到持久性單元有兩種方法,它們不應混用:
通過包配置屬性(例如 quarkus.hibernate-orm.conn.packages=your.package);
通過@io.quarkus.hibernate.orm.PersistenceUnit 包級注釋。
有關更多資訊,請閱讀https://quarkus.io/guides/hibernate-orm#multiple-persistence-units
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/414189.html
標籤:
