调用getter方法报 IllegalArgumentException的问题

尝试做一个SSH+spring security+blazeDS+flex的例子,修改用户信息的时候报了这么个怪异常
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of org.catablog.entity.IdEntity.entityId
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:195) [hibernate-core-3.3.1.GA.jar:3.3.1.GA]
	at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:206) [hibernate-core-3.3.1.GA.jar:3.3.1.GA]
.....
Caused by: java.lang.IllegalArgumentException: java.lang.ClassCastException@156f770
......


我操作的用户类定义如下

@Entity
//表名与类名不相同时重新定义表名.
@Table(name = "USERS")
//默认的缓存策略.
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class User extends IdEntity {

	private String loginName;
	private String password; //为简化演示,使用明文保存密码.
	private String name;
	private String email;

	private Set<Role> roles = new LinkedHashSet<Role>(); //有序的关联对象集合.

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}
	@Fetch(FetchMode.SUBSELECT)
	@LazyCollection(LazyCollectionOption.FALSE)
	@ManyToMany
	//多对多定义.
	@JoinTable(name = "USERS_ROLES", joinColumns = { @JoinColumn(name = "USER_ID") }, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID") })
	//集合按id排序.
	@OrderBy("entityId")
	//集合中对象的id的缓存.
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	//非持久化属性.
	@Transient
	public String getRoleNames() throws Exception {
		return ReflectionUtils.fetchElementPropertyToString(roles, "name", ", ");
	}

	//非持久化属性.
	@Transient
	@SuppressWarnings("unchecked")
	public List<Long> getRoleIds() throws Exception {
		return ReflectionUtils.fetchElementPropertyToList(roles, "id");
	}

}

entityId是我所有VO的公共父类,把ID的定义抽象出来了,从上面的异常消息可以看出是参数类型转换的时候报了类型转换非法异常,抛异常的是Hibernate的BasicPropertyAccessor,这可是Hibernate的基本组件,我在修改用户信息之前就已经查询过一次了,如果是我的entityId的类型有问题,那查询的时候就会调用BasicPropertyAccessor的get方法,那个时候就该报错了,也不该撑到这会儿。Debug了一下才发现User实例里的Roles集合里面全是ASObject?!怪不得,ASObject当然没有getter setter了。
刚开始纳闷儿怎么我的actionScript User类传到java这边就能转成对应的User类,User里的Role集合一过来就变成了ASObject?后来才明白,ActionScript不支持泛型的,Role类放进User里的Roles ArrayCollection的时候类型就没了,传到java那边儿当然识别不出Role的类型,就只能用ASObject替代了,这还真是个问题,延迟加载已经够让我头大的了,这个怎么说也得搞定!

你可能感兴趣的:(java,Hibernate,Flex,ssh,actionscript)