Active Objects ManyToMany reverse and through

How to use the reverse() and through() values for the @ManyToMany annotation?

Example;

@Table("KeychainUser")
public interface KeychainUserAO extends Entity {

@ManyToMany(value = UserAuthorizationAO.class, through = "getKeychainUser", reverse = "getUsers")
    PermissionAO[] getPermissions();

// next class, the 'through' class?

@Table("UserAuthorization")
public interface UserAuthorizationAO extends Entity {

    void setKeychainUser(KeychainUserAO keychainUser);

    KeychainUserAO getKeychainUser();

    void setPermission(PermissionAO permission);

    PermissionAO getPermission();
}

// the 'reverse' class?

@Table("Permission")
public interface PermissionAO extends Entity { 
    @ManyToMany(value = UserAuthorizationAO.class, through = "getPermission", reverse = "getPermissions")
    KeychainUserAO[] getUsers();
}

// exception
java.lang.IllegalArgumentException: public abstract nl.avisi.confluence.plugins.keychain.model.ao.KeychainUserAO[] nl.avisi.confluence.plugins.keychain.model.ao.PermissionAO.getUsers() has a ManyToMany annotation with an invalid reverse element value. It must be the name of the corresponding getter method on the joining entity.



This doesn't work.

2 answers

1 accepted

This widget could not be displayed.

Answer below;

KeychainUser class

@ManyToMany(value = UserAuthorizationAO.class, through = "getPermission", reverse = "getKeychainUser")
    PermissionAO[] getPermissions();

UserAuthorization class

void setKeychainUser(KeychainUserAO keychainUser);

    KeychainUserAO getKeychainUser();

    void setPermission(PermissionAO permission);

    PermissionAO getPermission();

Permission class

@ManyToMany(value = UserAuthorizationAO.class, through = "getKeychainUser", reverse = "getPermission")
    KeychainUserAO[] getUsers();

This widget could not be displayed.

Hi Patrick,

I'm not sure, but I think this should be:

@Table("KeychainUser")
public interface KeychainUserAO extends Entity {
 
@ManyToMany(value = UserAuthorizationAO.class, through = "getKeychainUser", reverse = "getPermission")
    PermissionAO[] getPermissions();
} 

 
@Table("UserAuthorization")
public interface UserAuthorizationAO extends Entity {
 
    void setKeychainUser(KeychainUserAO keychainUser);
 
    KeychainUserAO getKeychainUser();
 
    void setPermission(PermissionAO permission);
 
    PermissionAO getPermission();
}
 
@Table("Permission")
public interface PermissionAO extends Entity {
    @ManyToMany(value = UserAuthorizationAO.class, through = "getPermission", reverse = "getKeychainUser")
    KeychainUserAO[] getUsers();
}

Thanks for your answer! I'll try this once I've got the time for it.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in Teamwork

What teamwork quotes inspire you?

Hey everyone! My name is Natalie and I'm an editor of the Atlassian Blog and I've got a question for you: What's your favorite quote about teamwork?  We've compiled a list here, along with...

150 views 16 7
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you