Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Micronaut SQL JPA requires Micronaut Data Model dependency #1157

Open
sdelamo opened this issue Nov 11, 2023 · 4 comments · Fixed by micronaut-projects/micronaut-gradle-plugin#869
Labels
type: bug Something isn't working

Comments

@sdelamo
Copy link
Contributor

sdelamo commented Nov 11, 2023

I expected the following dependencies to be enough:

    implementation("io.micronaut.data:micronaut-data-tx-hibernate")
    implementation("io.micronaut.sql:micronaut-hibernate-jpa")
    implementation("io.micronaut.sql:micronaut-jdbc-hikari")
    runtimeOnly("com.h2database:h2")

but without:

    implementation("io.micronaut.data:micronaut-data-model")

We don't mention in the docs micronaut-data-model is necessary.

Without it, I get:

Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.NoClassDefFoundError: io/micronaut/data/annotation/GeneratedValue$Type [in thread "Test worker"]

This is the domain of the sample app:

package example.micronaut.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;

import io.micronaut.serde.annotation.Serdeable;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
import java.util.HashSet;
import java.util.Set;

import static jakarta.persistence.GenerationType.AUTO;

@Serdeable
@Entity
@Table(name = "genre")
public class Genre {

    @Id
    @GeneratedValue(strategy = AUTO)
    private Long id;

    @NotNull
    @Column(name = "name", nullable = false, unique = true)
    private String name;

    @JsonIgnore
    @OneToMany(mappedBy = "genre")
    private Set<Book> books = new HashSet<>();

    public Genre() {}

    public Genre(@NotNull String name) {
        this.name = name;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Set<Book> getBooks() {
        return books;
    }

    public void setBooks(Set<Book> books) {
        this.books = books;
    }

    @Override
    public String toString() {
        return "Genre{" +
            "id=" + id +
            ", name='" + name + '\'' +
            '}';
    }
}

Steps to reproduce:

clone https://github.com/grails-core-issues-forks/micronaut-sql-1157

cd ../micronaut-jpa-hibernate-gradle-java
./gradlew test
@sdelamo sdelamo added the type: bug Something isn't working label Nov 11, 2023
@sdelamo
Copy link
Contributor Author

sdelamo commented Nov 11, 2023

@dstepanov do you know what could be going on?

melix added a commit to micronaut-projects/micronaut-gradle-plugin that referenced this issue Nov 14, 2023
In some circumstances, automatic dependencies can get in the way. This
should be rare but there was no built-in mechanism to ignore such
dependencies. It is now possible to list these using the `micronaut`
extension, for example:

```
micronaut {
    ignoredAutomaticDependencies.add("io.micronaut.data:micronaut-data-processor")
}
```

The responsibility of adding these is then shifted to the user.

Fixes micronaut-projects/micronaut-sql#1157
sdelamo pushed a commit to micronaut-projects/micronaut-gradle-plugin that referenced this issue Nov 14, 2023
In some circumstances, automatic dependencies can get in the way. This
should be rare but there was no built-in mechanism to ignore such
dependencies. It is now possible to list these using the `micronaut`
extension, for example:

```
micronaut {
    ignoredAutomaticDependencies.add("io.micronaut.data:micronaut-data-processor")
}
```

The responsibility of adding these is then shifted to the user.

Fixes micronaut-projects/micronaut-sql#1157
@sdelamo sdelamo reopened this Nov 14, 2023
@radovanradic
Copy link
Contributor

radovanradic commented Jan 26, 2024

Don't know how and when this started to happen, but for some reason generated introspection classes for Genre and Book contain imports

import io.micronaut.data.annotation.GeneratedValue.Type;
import io.micronaut.data.annotation.Relation.Kind;
import io.micronaut.data.model.DataType;

and introspection is used when building session factory so that is when exception is thrown. Feels like io.micronaut.data.model.* imports shouldn't be here because Genre and Book have jakarta annotations but don't know why are these being used as micronaut-data-processor (ie annotation mapper) is not supposed be used here but maybe @dstepanov knows what is going on here.

@dstepanov
Copy link
Contributor

When did it appear? I think we always remapped to our annotations.

This might be improved by not generating the enum reference but a simple string.

@radovanradic
Copy link
Contributor

I didn't realize first that data-processor is added as dependency through gradle (and in maven it's not added) so that is doing mapping and adding dependencies for data-model in the generated introspections. Tried this in 3.x and gives the same error, so not sure what and when changed that we now need to add data-model explicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants