micronaut-projects / micronaut-projects/micronaut-sql

Micronaut SQL JPA requires Micronaut Data Model dependency

Open
#1,157 4 comments 0 reactions 0 assignees View on GitHub
type: bug
Dominant language
Java
Stars
83
Forks
49
Avg merge
1d 10h
Merged PRs (30d)
22

Description

I expected the following dependencies to be enough:

```groovy
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:

```groovy
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:

```java
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 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 getBooks() {
return books;
}

public void setBooks(Set 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
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Clone the linked reproduction, enter micronaut-jpa-hibernate-gradle-java, and run ./gradlew test to observe the missing dependency failure. Find the documentation for this Micronaut SQL JPA sample and document micronaut-data-model alongside the other required dependencies; done means the documented setup avoids the reported NoClassDefFoundError.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
database, documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.