helplessMax
helplessMax

Reputation: 93

Quarkus build failure in hibernate: Multiple persistence units are defined but the entities are not mapped to them

I can't seem to get my Postgresql database working with quarkus and hibernate. There is no examples of the error I'm getting anywhere:

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.

This is my 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

I'm trying to bind it in my class like this:

@ApplicationScoped
public class Service {

    @Inject
    @PersistenceContext(unitName = "conn")
    protected EntityManager eventEM;
...

Trying to bind it with @PersistenceUnit(...) does not work either.

I have multiple entities which I am trying to bind as follows:

@Entity
@Table(name = "name")

@NoArgsConstructor
@Getter
@EqualsAndHashCode
@ToString
public class MyEntity {

    @Id
    @Column(name = "id", updatable = false)
    private String id;
...

Shouldn't this work without a persistence.xml?

Really appreciate it! :)

Upvotes: 4

Views: 9968

Answers (1)

Edgar Domingues
Edgar Domingues

Reputation: 990

You need to attach your entity packages to persistence units.

There are two ways to attach model classes to persistence units, and they should not be mixed:

  • Via the packages configuration property (e.g. quarkus.hibernate-orm.conn.packages=your.package);

  • Via the @io.quarkus.hibernate.orm.PersistenceUnit package-level annotation.

For more info please read https://quarkus.io/guides/hibernate-orm#multiple-persistence-units

Upvotes: 2

Related Questions