Would it be possible to declare a HashMap in the following object called Group?
Doing something like this doesn't work:
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "group")
@MapKey(name = "member.name")
private Map<String, GroupMember> groupMembers = new HashMap<String, GroupMember>();
StackTrace:
12:07:51 [INFO] [Groups] Enabling Groups v0.1
12:07:51 [SEVERE] Error occurred while enabling Groups v0.1 (Is it up to date?)
java.lang.RuntimeException: An exception has occured while initializing the database
at groups.storage.MyDatabase.initializeDatabase(MyDatabase.java:83)
at groups.storage.Dao.<init>(Dao.java:26)
at groups.Groups.onEnable(Groups.java:30)
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:457)
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:381)
at org.bukkit.craftbukkit.v1_5_R2.CraftServer.loadPlugin(CraftServer.java:282)
at org.bukkit.craftbukkit.v1_5_R2.CraftServer.enablePlugins(CraftServer.java:264)
at org.bukkit.craftbukkit.v1_5_R2.CraftServer.reload(CraftServer.java:605)
at org.bukkit.Bukkit.reload(Bukkit.java:184)
at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23)
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:188)
at org.bukkit.craftbukkit.v1_5_R2.CraftServer.dispatchCommand(CraftServer.java:523)
at org.bukkit.craftbukkit.v1_5_R2.CraftServer.dispatchServerCommand(CraftServer.java:512)
at net.minecraft.server.v1_5_R2.DedicatedServer.am(DedicatedServer.java:261)
at net.minecraft.server.v1_5_R2.DedicatedServer.r(DedicatedServer.java:226)
at net.minecraft.server.v1_5_R2.MinecraftServer.q(MinecraftServer.java:474)
at net.minecraft.server.v1_5_R2.MinecraftServer.run(MinecraftServer.java:407)
at net.minecraft.server.v1_5_R2.ThreadServerApplication.run(SourceFile:573)
Caused by: java.lang.RuntimeException: Failed to create a new instance of the EbeanServer
at groups.storage.MyDatabase.loadDatabase(MyDatabase.java:162)
at groups.storage.MyDatabase.initializeDatabase(MyDatabase.java:77)
... 18 more
Caused by: javax.persistence.PersistenceException: groups.model.Group: Could not find mapKey property [member.name] on [groups.model.GroupMember]
at com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocMany.initMapKeyProperty(BeanPropertyAssocMany.java:744)
at com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocMany.initialise(BeanPropertyAssocMany.java:147)
at com.avaje.ebeaninternal.server.deploy.BeanDescriptor.initialiseOther(BeanDescriptor.java:763)
at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.initialiseAll(BeanDescriptorManager.java:403)
at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.deploy(BeanDescriptorManager.java:293)
at com.avaje.ebeaninternal.server.core.InternalConfiguration.<init>(InternalConfiguration.java:150)
at com.avaje.ebeaninternal.server.core.DefaultServerFactory.createServer(DefaultServerFactory.java:209)
at com.avaje.ebeaninternal.server.core.DefaultServerFactory.createServer(DefaultServerFactory.java:64)
at com.avaje.ebean.EbeanServerFactory.create(EbeanServerFactory.java:78)
at groups.storage.MyDatabase.loadDatabase(MyDatabase.java:159)
... 19 more
...
@Entity
@Table(name = "groups_group")
public class Group {
public enum Type {
Include,
Exclude
}
@Id
@GeneratedValue
@Column(name = "id", unique = true, nullable = false)
private Integer id;
@Column(name = "name", unique = true, nullable = false, length = 25)
private String name;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "group")
@MapKey(name = "member.name")
private Map<String, GroupMember> groupMembers = new HashMap<String, GroupMember>();
@Column(name = "personal", nullable = false)
private Boolean personal = false;
@Enumerated(value = EnumType.ORDINAL)
@Column(name = "type", nullable = false, length = 2)
private Type type = Type.Include;
@Column(name = "password", nullable = true, length = 16)
private String password;
@Version
@Column(name = "update_time", nullable = false)
Timestamp updatetime;
@CreatedTimestamp
@Column(name = "create_time", nullable = false)
Timestamp createTime;
public Group() {}
//getters and setters
}
..
@Entity
@Table(name = "groups_group_member")
public class GroupMember {
public enum Role {
ADMIN,
MODERATOR,
MEMBER,
BANNED
}
@Id
@GeneratedValue
@Column(name = "id", unique = true, nullable = false)
private Integer id;
@ManyToOne
@JoinColumn(name = "group_id")
private Group group;
@ManyToOne
@JoinColumn(name = "member_id")
private Member member;
@Enumerated(value = EnumType.ORDINAL)
@Column(name = "role", nullable = false, length = 2)
private Role role = Role.MEMBER;
@Version
@Column(name = "update_time", nullable = false)
Timestamp updatetime;
@CreatedTimestamp
@Column(name = "create_time", nullable = false)
Timestamp createTime;
public GroupMember() {}
//getters and setters...
}
...
@Entity
@Table(name = "groups_member")
public class Member {
@Id
@GeneratedValue
@Column(name = "id", unique = true, nullable = false)
private Integer id;
@Column(name = "name", unique = true, nullable = false, length = 16)
private String name;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "member")
private Set<GroupMember> groupMembers = new HashSet<GroupMember>();
@Version
@Column(name = "update_time", nullable = false)
Timestamp updatetime;
@CreatedTimestamp
@Column(name = "create_time", nullable = false)
Timestamp createTime;
public Member() {}
//getters and setters
}