java - Ebean record fails to pick up on a relationship -
i having trouble ebean/play not picking licks between tables.
i have 3 tables, users, groups , usersgroups (bridge).
i have record in each table , when pick users record, object has access associated usersgroups records. when try same groups linked usersgroups object empty. have little experience orms , have no idea how can debug issue.
users class:
@entity public class users extends model { @id @generatedvalue(strategy = generationtype.auto) public long intuserid; @javax.persistence.column(length = 50, unique = true) @constraints.required public string strusername; @onetomany(mappedby = "user", fetch = fetchtype.eager, cascade = cascadetype.all) public list<sessions> session; @onetomany(mappedby = "member", cascade = cascadetype.all) public list<usersgroups> memberofgroups; @javax.persistence.column(length = 50) public string strfirstname; @javax.persistence.column(length = 50) public string strlastname; @javax.persistence.column(length = 50, unique = true) @constraints.required public string stremail; @formats.datetime(pattern = "dd/mm/yyyy") public date tsregistrationdate = new date(); public string strpasswordhash; public static finder<long, users> find = new finder(long.class, users.class); }
groups class:
@entity public class groups extends model { @id @constraints.required @column(unique = true) @generatedvalue(strategy = generationtype.auto) public long intgroupid; @transient public long inttoken() { return this.intgroupid + 100000; } @onetomany(mappedby = "group", cascade = cascadetype.all) public list<usersgroups> usersgroups; @constraints.required @formats.datetime(pattern = "dd/mm/yyyy") public date tscreated = new date(); @constraints.required @javax.persistence.column(length = 2) public long inttype; @constraints.required @javax.persistence.column(length = 2) public long intstatus = (long) 1; @constraints.required @javax.persistence.column(length = 50) public string strname; @constraints.required public boolean blpublic; public static finder<long, groups> find = new finder(long.class, groups.class); }
bridge class:
@entity public class usersgroups extends model { @manytoone(cascade=cascadetype.all) @joincolumn(name = "int_user_id") public users member; @manytoone(cascade=cascadetype.all) @joincolumn(name = "int_group_id") public groups group; public int type; public static finder<long, usersgroups> find = new finder(long.class, usersgroups.class); }
now issue:
system.out.println("group: "+ group.intgroupid); system.out.println("ugroup: "+ ebean.group(usersgroups.class ).where().eq("int_group_id", group.intgroupid).findrowcount()); system.out.println(group.usersgroups.size());
prints:
group: 12 ugroup: 1 0
from gather 1. groups object found, 2. associated record in bridge table found, 3. ebean fails pick link.
help appreciated.