0

I have a basic database JPA setup with the following structure in project A:

└── src
    ├── main
    │   ├── java
    │   │   └── com
    │   │       └── my
    │   │           └── apps
    │   │               └── org
    │   │                   └── helidonapp
    │   │                       ├── Application.java
    │   │                       ├── application
    │   │                       │   ├── Employee
    │   │                       │   │   ├── EmployeeController.java
    │   │                       │   │   └── EmployeeRepository.java
    │   │                       │   ├── MyDataSource.java
    │   │                       ├── domain
    │   │                       │   └── model
    │   │                       │       └── Employee.java
    │   └── resources
    │       ├── META-INF
    │       │   ├── beans.xml
    │       │   ├── microprofile-config-local.properties
    │       │   ├── microprofile-config.properties
    │       │   └── persistence.xml
    │       └── log4j2.xml

Which, when I compile and run project A, it connects to the database and I can make REST calls to the API without any issues.

However, I want to shift the database configuration to an external maven library (let's call this project B).

Project B now has the following structure:

database-utils
   ├── pom.xml
   └── src
       ├── main
          ├── java
          │   └── com
          │       └── my
          │           └── apps
          │               └── ic
          │                   ├── Entity
           |                   │       ├── GenericController.java
           |                    │       └── GenericRepository.java
            |                    ├── domain
           |                    │   └── model
           |                    │       └── AbstractEntity.java
          │                   ├──
          │                   └── persistence
          │                       └── jpa
          │                           └── MyDataSource.java
          └── resources
              └── META-INF
                  ├── persistence.xml
                   

And my child project (Project A) now has this structure:

src
    ├── main
    │   ├── java
    │   │   └── com
    │   │       └──  my
    │   │           └── apps
    │   │               └── org
    │   │                   └── helidon
    │   │                       ├── Application.java
    │   │                       ├── application
    │   │                       │   └── Employee
    │   │                       │       ├── EmployeeController.java 
    │   │                       │       └── EmployeeRepository.java
                                ├── domain
                               │   └── model
                               │       └── Employee.java
    │   └── resources
    │       ├── META-INF
    │       │   ├── beans.xml
    │       │   ├── microprofile-config-local.properties
    │       │   └── microprofile-config.properties

(Note: EmployeeController and EmployeeRepository both extend their Generic equivalents from project B)

However, when I compile and run newly configured Project A I get the following error:

Exception in thread "main" jakarta.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 3.0.3.v202208191135): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [myPu] failed.
Internal Exception: org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001334: Unsatisfied dependencies for type DataSource with qualifiers @Default @Named
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.createPredeployFailedPersistenceException(EntityManagerSetupImpl.java:2153)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:2129)
    at org.eclipse.persistence.jpa.PersistenceProvider.createContainerEntityManagerFactoryImpl(PersistenceProvider.java:350)

I am unsure why the above error is happening, I looked up possible causes but could not find anything regarding having a db setup on an external library.

My theory is the persistence.xml cannot find the DataSource class, but I checked to see that my project B's module .jar file is included under target/libs in project A. I also looked inside the .jar file and did see the DataSource, persistence.xml, and other controller/repository class files are available. I double checked that the @Named annotation value in my datasource class matches the tag in persistence.xml

swing1234
  • 233
  • 1
  • 3
  • 13
  • At root, this is a `DataSource` discovery problem and you should be able to isolate it without reference to all the JPA stuff. Specifically, to me it looks like project B has no `META-INF/beans.xml` classpath resource, and is thus not a CDI bean archive, and so CDI cannot "see" the `DataSource` that you know to be in it. See also https://github.com/helidon-io/helidon/wiki/FAQ#how-do-i-make-a-class-a-cdi-bean – Laird Nelson Aug 21 '23 at 16:44

0 Answers0