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

Hibernate Reactive: Issues with 'findAllBy' when using a property whose name is a part of another property's name #2474

Closed
fdittz opened this issue Aug 31, 2023 · 1 comment · Fixed by #2498
Assignees
Labels
type: bug Something isn't working
Milestone

Comments

@fdittz
Copy link

fdittz commented Aug 31, 2023

Expected Behavior

I'm currently porting a system that uses Spring Data JPA to Micronaut using Hibernate Reactive, and I have the following entities:

@Entity
@Data
public class UserGroupMembership {

    @Id
    private Long uid;

    @ManyToOne(fetch = FetchType.EAGER)
    private UserGroup userGroup;

    @ManyToOne(fetch = FetchType.EAGER)
    private User user;

}
@Entity 
@Data 
public class UserGroup {

@Id
private Long uid;

@OneToMany(mappedBy="userGroup", fetch = FetchType.LAZY)
private Set<UserGroupMembership> userAuthorizations = new HashSet<UserGroupMembership>();

@ManyToOne
private Area area;

}
@Entity 
@Data 
public class Area {
    
    @Id
    private Long uid;
    
    @ManyToOne
    private Area parent;
    
    @ManyToOne(fetch = FetchType.LAZY)
    private ApplicationEnvironment applicationEnvironment;
    
}

And the repository:

@Repository
public interface UserGroupMembershipRepository extends ReactiveStreamsCrudRepository<UserGroupMembership, Long> {

    Flux<UserGroupMembership> findAllByUserLogin(String login);
    
    
    @Join(value = "userGroup.area", type = Join.Type.FETCH)
    Flux<UserGroupMembership> findAllByUserLoginAndUserGroupAreaUid(String login, Long uid);

}

The method findAllByUserLoginAndUserGroupAreaUid(String login, Long uid) should return all UserGroupMemberships for a specific user and only UserGroups that belong to a given Area UID

Actual Behaviour

It fails to correctly identify the properties:
java: Unable to implement Repository method: UserGroupMembershipRepository.findAllByUserLoginAndUserGroupAreaUid(String login,Long uid). Cannot query entity [UserGroupMembership] on non-existent property: UserGroupAreaUid

It tries to find a property named UserGroupAreaUid, which doesn't exist, instead of going through the relationships.
I tried adding a separator to the method definition to explicitly separate property names, thus declaring it as findAllByUserLoginAndUserGroup_AreaUid(String login,Long uid) , but got the same result

java: Unable to implement Repository method: UserGroupMembershipRepository.findAllByUserLoginAndUserGroup_AreaUid(String login,Long uid). Cannot query entity [UserGroupMembership] on non-existent property: UserGroup_AreaUid

What did the trick was exchanging private User user; in my UserGroupMembership entity for private User member; and then changing the findAllBy definition accordingly: findAllByMemberLoginAndUserGroupAreaUid(String login, Long uid)

I believe this is a bug caused by having fields named user and userGroup

Steps To Reproduce

No response

Environment Information

  • Amazon Corretto 17.0.5.8.1
  • Ubuntu 22.04

Example Application

No response

Version

4.0.5

@radovanradic
Copy link
Contributor

@fdittz After 4.1.3 or 4.2.0, not sure which will be next release, this should be doable with method like this:

@Join(value = "userGroup.area", type = Join.Type.FETCH)
Flux<UserGroupMembership> findAllByUserLoginAndUserGroup_AreaUid(String login, Long uid);

using underscore, like suggested here

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
2 participants