0

I have two tables

  • RoleMasterLink with userId and RoleId
  • RoleMaster with RoleId and FunctionalRole

I need to achive

Select rm.FunctionalRole from RoleMaster rm join RoleMasterLink rml on rml.RoleId = rm.RoleId where rml.userId='yesh'

User can have many roleIds, I need to get FunctionalRole based on RoleId

How to achive this with Spring Data Jpa, gone through many links but exactly couldn't get.

2
  • What do you want as return type? String? Commented Dec 16, 2017 at 13:45
  • Return type will be List of Strings , say User ID has three RoleIds, we should match and get the Functional Roles. Looks like simple requirement but I am missing some annotations in model class. Commented Dec 17, 2017 at 14:31

1 Answer 1

2

Simply add your query in a @Query annotation in your Repository interface:

@Query("Select rm.FunctionalRole from RoleMaster rm join RoleMasterLink rml on rml.RoleId = rm.RoleId where rml.userId= :userId")
String findFunctionalRole(String userId);
Sign up to request clarification or add additional context in comments.

2 Comments

I tried same query , can you give code, like in RoleMasterLink and RoleMaster which annotations should I give to achive this, like join Column () and one-to-one and mapping by...
Can you please post the classes RoleMaster and RoleMasterLink ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.