mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Fix for Issue 72 - Bug - models.Role cannot be cast to java.util.Map [error] at com.avaje.ebeaninternal.server.persist.DefaultPersister.saveAssocManyDetails(DefaultPersister.java:877)
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package com.avaje.tests.model.map;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
public class MpRole {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
private Long organizationId;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getOrganizationId() {
|
||||
return organizationId;
|
||||
}
|
||||
|
||||
public void setOrganizationId(Long organizationId) {
|
||||
this.organizationId = organizationId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.avaje.tests.model.map;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
public class MpUser {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL)
|
||||
@MapKey(name = "id")
|
||||
public Map<Long, MpRole> roles = new HashMap<Long, MpRole>();
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Map<Long, MpRole> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void setRoles(Map<Long, MpRole> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.avaje.tests.query.other;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.tests.model.map.MpRole;
|
||||
import com.avaje.tests.model.map.MpUser;
|
||||
|
||||
public class TestOneToManyAsMap extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
EbeanServer eServer = Ebean.getServer(null);
|
||||
|
||||
MpUser u = new MpUser();
|
||||
eServer.save(u);
|
||||
|
||||
MpUser u2 = eServer.find(MpUser.class, u.getId());
|
||||
Assert.assertNotNull(u2);
|
||||
|
||||
u2.setName("Charlie Brown");
|
||||
MpRole ourl = new MpRole();
|
||||
ourl.setOrganizationId(47L);
|
||||
u2.getRoles().put(ourl.getOrganizationId(), ourl);
|
||||
eServer.save(u2);
|
||||
|
||||
MpUser u3 = eServer.find(MpUser.class, u.getId());
|
||||
Assert.assertEquals("Charlie Brown", u3.getName());
|
||||
|
||||
Map<Long, MpRole> listMap = u3.getRoles();
|
||||
Assert.assertEquals(1, listMap.size());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user