jboss seam 多对多配置,主键序列生成,异常: Could not synchronize database state with session
ERROR [BasicPropertyAccessor] IllegalArgumentException in class: org.domain.jbossseamtmsoa.entity.Role, getter method of property: roleid
17:22:37,137 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of org.domain.jbossseamtmsoa.entity.Role.roleid
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:195)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:206)
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3619)
at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3335)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:204)
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:241)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:430)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:101)
at org.hibernate.persister.collection.AbstractCollectionPersister.writeElement(AbstractCollectionPersister.java:777)
at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
......(SecurityContextEstablishmentValve.java:126)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
......
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:169)
... 103 more
Role.:
/**
* Role generated by hbm2java
*/
@Entity
@Table(name = "ROLE", schema = "SEAM_TMS_OA", uniqueConstraints = @UniqueConstraint(columnNames = "ROLENAME"))
public class Role implements java.io.Serializable {
private int roleid;
private String rolename;
private String description;
private String isdelete;
private Set<OaUser> users = new HashSet<OaUser>(0);
private Set<Menu> menus = new HashSet<Menu>(0);
public Role() {
}
public Role(int roleid, String rolename) {
this.roleid = roleid;
this.rolename = rolename;
}
public Role(int roleid, String rolename, String description, String isdelete) {
this.roleid = roleid;
this.rolename = rolename;
this.description = description;
this.isdelete = isdelete;
}
@Id
@Column(name = "ROLEID", unique = true, nullable = false, precision = 8, scale = 0)
@SequenceGenerator(name = "seq_role", sequenceName = "seq_role", allocationSize = 1)
@GeneratedValue(generator = "seq_role", strategy = GenerationType.SEQUENCE)
public int getRoleid() {
return this.roleid;
}
public void setRoleid(int roleid) {
this.roleid = roleid;
}
@Column(name = "ROLENAME", unique = true, nullable = false, length = 30)
@NotNull
@Length(max = 30)
public String getRolename() {
return this.rolename;
}
public void setRolename(String rolename) {
this.rolename = rolename;
}
@Column(name = "DESCRIPTION", length = 300)
@Length(max = 300)
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
@ManyToMany(mappedBy="roles")
@JoinTable(name = "user_role", inverseJoinColumns = @JoinColumn(name = "userid"), joinColumns = @JoinColumn(name = "roleid"))
public Set<OaUser> getUsers() {
return users;
}
public void setUsers(Set<OaUser> users) {
this.users = users;
}
@ManyToMany(targetEntity=Role.class)
@JoinTable(name = "menu_role", inverseJoinColumns = @JoinColumn(name = "menuid"), joinColumns = @JoinColumn(name = "roleid"))
public Set<Menu> getMenus() {
return menus;
}
public void setMenus(Set<Menu> menus) {
this.menus = menus;
}
@Column(name = "ISDELETE", length = 2)
@Length(max = 2)
public String getIsdelete() {
return this.isdelete;
}
public void setIsdelete(String isdelete) {
this.isdelete = isdelete;
}
}
@Name("roleHome")
public class RoleHome extends EntityHome<Role> {
/**
* OA 角色管理
*/
private static final long serialVersionUID = -4315663157458269975L;
private List<Integer> menuidList;
public List<Integer> getMenuidList() {
menuidList = new ArrayList<Integer>();
Set<Menu> menus = this.instance.getMenus();
if (menus != null && menus.size() > 0) {
for (Iterator iterator = menus.iterator(); iterator.hasNext();) {
Menu menu = (Menu) iterator.next();
menuidList.add(menu.getMenuid());
}
}
return menuidList;
}
public void setRoleRoleid(Integer id) {
setId(id);
}
public Integer getRoleRoleid() {
return (Integer) getId();
}
@Override
protected Role createInstance() {
Role role = new Role();
return role;
}
public void load() {
if (isIdDefined()) {
wire();
}
}
public void wire() {
getInstance();
}
public boolean isWired() {
return true;
}
public Role getDefinedInstance() {
return isIdDefined() ? getInstance() : null;
}
@Override
public String persist() {
if (menuidList != null && menuidList.size() > 0) {
Set<Menu> menus = new HashSet<Menu>();
Menu menu = new Menu();
for (Iterator iterator = menuidList.iterator(); iterator.hasNext();) {
String menuid = (String) iterator.next();
menu.setMenuid(Integer.parseInt(menuid.trim()));
menus.add(menu);
}
this.instance.setMenus(menus);
}
return super.persist();
}
@Override
public String update() {
if (menuidList != null && menuidList.size() > 0) {
Set<Menu> menus = new HashSet<Menu>();
Menu menu = new Menu();
for (Iterator iterator = menuidList.iterator(); iterator.hasNext();) {
String menuid = (String) iterator.next();
menu.setMenuid(Integer.parseInt(menuid.trim()));
menus.add(menu);
}
this.instance.setMenus(menus);
}
return super.update();
}
public void setMenuidList(List<Integer> menuidList) {
this.menuidList = menuidList;
}
}
jboss seam :实现角色-菜单的配置,(多对多),角色的主键是Secquence,,,,,问题应该是出在主键Roleid上,但不知道怎么解决》》》在此向各位请教,谢谢!
[解决办法]
最近怎么那么冷清,发了好几个贴,都没人回???
[解决办法]
搞定,关系配置有误
[解决办法]
高手能教教我吗,我遇到同样的问题,谢谢!