报错 could not initialize a collection: [com.twitter.entity.Role.actions#20]

最近用struts2.8+hibernate3.5+spring3.0+annotations写项目,用到了Hibernate注解,其中有实体关系用到注解如:

Role实体

@SuppressWarnings("serial")
@Entity
@Table(name = "role")
public class Role implements java.io.Serializable {

    // Fields
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name="id",unique=true)
    private Integer id;
	@Column(name="roleName",length=50,nullable=false)
	private String roleName;//角色名称
	@Column(name="roleInfo",length=1000)
	private String roleInfo;//角色介绍
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="createTime",nullable=false)
	private Date createTime;//创建时间

	@ManyToMany(cascade={CascadeType.MERGE,CascadeType.REFRESH},fetch=FetchType.LAZY)
	@JoinTable(name="roleaction",inverseJoinColumns={@JoinColumn(name="actionId")},joinColumns={@JoinColumn(name="roleId")})
    private Set<Action> actions = new HashSet<Action>(0);
	
	@ManyToMany(cascade={CascadeType.MERGE,CascadeType.REFRESH},fetch=FetchType.LAZY)
	@JoinTable(name="userrole",inverseJoinColumns={@JoinColumn(name="userId")},joinColumns={@JoinColumn(name="roleId")})
	private Set<UserInfo> users=new HashSet(0);
	
	@ManyToMany(cascade={CascadeType.MERGE,CascadeType.REFRESH},fetch=FetchType.LAZY)
	@JoinTable(name="rolemenu",inverseJoinColumns={@JoinColumn(name="menuId")},joinColumns={@JoinColumn(name="roleId")})
	private Set<Menu> menus=new HashSet(0);

 Action实体

@SuppressWarnings("serial")
@Entity
@Table(name = "action")
public class Action implements java.io.Serializable {
    // Fields
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name="id",unique=true)
	private int id;
	@Column(name="actionName",length=50)
	private String actionName;//动作名称(例如增加,删除)
	@Column(name="path",length=100,nullable=false)
	private String path;//相对于主目录的路径
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="createTime",nullable=false)
	private Date createTime;//创建时间
	@Column(name="orders",nullable=false)
	private int orders;//排序
	
	//多对一
	@ManyToOne(cascade={CascadeType.REFRESH,CascadeType.MERGE},fetch=FetchType.LAZY ,optional = false)
    @JoinColumn(name = "moduleId")     
	private Module module ;//模块
	//多对多
	@ManyToMany()
	@JoinTable(name="roleaction",inverseJoinColumns={@JoinColumn(name="roleId")},joinColumns={@JoinColumn(name="actionId")})
	private Set<Role> roles = new HashSet<Role>(0);//角色集合多对多关联

 

后来加载到这里两个类时报错

信息: Creating new cache
Hibernate: select roles0_.userId as userId0_1_, roles0_.roleId as roleId1_, role1_.id as id2_0_, role1_.createTime as createTime2_0_, role1_.roleInfo as roleInfo2_0_, role1_.roleName as roleName2_0_ from userrole roles0_ inner join role role1_ on roles0_.roleId=role1_.id where roles0_.userId=?
Hibernate: select actions0_.roleId as roleId2_1_, actions0_.actionId as actionId1_, action1_.id as id1_0_, action1_.actionName as actionName1_0_, action1_.createTime as createTime1_0_, action1_.moduleId as moduleId1_0_, action1_.orders as orders1_0_, action1_.path as path1_0_ from roleaction actions0_ inner join action action1_ on actions0_.actionId=action1_.id where actions0_.roleId=?
2011-4-8 15:35:53 org.apache.jsp.commons.error_jsp _jspService
严重: could not initialize a collection: [com.twitter.entity.Role.actions#20]
org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.twitter.entity.Role.actions#20]
	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
	at org.hibernate.loader.Loader.loadCollection(Loader.java:2069)
	at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:62)
	at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:628)
	at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
	at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1853)
	at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:366)
	at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108)
	at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:186)
	at com.twitter.web.struts2.action.UserInfoAction.login(UserInfoAction.java:68)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

 

 就是没找到原因?有知道的帮帮我,感谢!

 

 

问题解决了!

不好意思,我才发现我数据库中确实没有action这张表,所以报找不到错误!这么低级对不住了!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值