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

BeanDefinitions being generated for @Entity in 3.7.0 #8096

Closed
sdelamo opened this issue Sep 28, 2022 · 1 comment
Closed

BeanDefinitions being generated for @Entity in 3.7.0 #8096

sdelamo opened this issue Sep 28, 2022 · 1 comment
Assignees
Labels
type: bug Something isn't working

Comments

@sdelamo
Copy link
Contributor

sdelamo commented Sep 28, 2022

For an application generated with the hibernate-jpa feature, starting 3.7.0 we are generating bean bean definitions for classes annotated with javax.persistence.Entity.

for this entity

package com.example;

import io.micronaut.core.annotation.Creator;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;

@Entity
@Table(name = "account")
public class Account {

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

    @Column(name = "username", nullable = false)
    @NotBlank
    private String username;

    @Column(name = "password", nullable = false)
    @NotBlank
    private String password;

    public Long getId() {
        return id;
    }

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

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

The following test will pass for 3.7.0

package com.example;

import io.micronaut.context.BeanContext;
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;

@MicronautTest(startApplication = false)
class AccountTest {

    @Inject
    BeanContext beanContext;

    @Test
    void beanDefinitions() {
        assertFalse(beanContext.getBeanDefinitions(Account.class).isEmpty());
    }
}

It will fail for 3.6.3.

Is this expected behaviour?

@dstepanov
Copy link
Contributor

Looks like my changes making an entity a bean because of the validation annotations

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
None yet
Development

No branches or pull requests

3 participants