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

Fix entity becoming a bean #8098

Merged
merged 1 commit into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ public Object visitExecutable(ExecutableElement method, Object o) {
writer.setValidated(validatedMethod);
}
}
} else if (validatedMethod) {
} else if (validatedMethod && isDeclaredBean) {
if (isPrivate) {
error(method, "Method annotated with constraints but is declared private. Change the method to be non-private in order for AOP advice to be applied.");
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.micronaut.inject.validation;

import javax.annotation.Nullable;
import javax.persistence.Entity;
import javax.validation.constraints.NotBlank;

@Entity
public class Account1 {

private Long id;

@Nullable
@NotBlank
private String username;

@Nullable
@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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.micronaut.inject.validation;

import javax.persistence.Entity;
import javax.validation.constraints.NotBlank;

@Entity
public class Account2 {

private Long id;

private String username;

private String password;

public Long getId() {
return id;
}

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

@NotBlank
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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.micronaut.inject.validation;

import javax.annotation.Nullable;
import javax.persistence.Entity;
import javax.validation.constraints.NotBlank;

@Entity
@Nullable
public class Account3 {

private Long id;

private String username;

private String password;

public Long getId() {
return id;
}

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

@NotBlank
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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.micronaut.inject.validation

import io.micronaut.context.ApplicationContext
import spock.lang.AutoCleanup
import spock.lang.Shared
import spock.lang.Specification

class BeanWithValidationSpec extends Specification {

@Shared @AutoCleanup ApplicationContext context = ApplicationContext.run()

void 'test bean definition is not created for a bean with validation'() {
expect:
context.getBeanDefinitions(Account1.class).isEmpty()
context.getBeanDefinitions(Account2.class).isEmpty()
context.getBeanDefinitions(Account3.class).isEmpty()
}
}