Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Active Objects ManyToMany reverse and through

Patrick van der Rijst
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 27, 2013

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

1 vote
Answer accepted
Patrick van der Rijst
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 20, 2013

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();

0 votes
resah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 8, 2013

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();
}

Patrick van der Rijst
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 8, 2013

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
TAGS
AUG Leaders

Atlassian Community Events