最近用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这张表,所以报找不到错误!这么低级对不住了!
分享到:
相关推荐
标题 "Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser" 提示了一个Java运行时错误,这通常意味着在尝试加载或初始化`JRStyledTextParser`类时遇到了问题。`JRStyledTextParser`是...
监听COM口启动程序报错 Could not initialize class gnu.io.RXTXCommDriver异常 是因为需要在%JAVA_HOME%/jre/bin目录中添加rxtxParallel.dll、rxtxSerial.dll文件
在使用PL/SQL Developer 12连接Oracle数据库时,可能会遇到“Could not initialize oci.dll”这样的错误提示。这个错误通常表明系统无法找到或正确加载Oracle客户端的oci.dll库文件,这是Oracle Instant Client的一...
内涵jacob_1.14.3-x64.dll;jacob_1.14.3-64.jdk(maven地址);解决方法:Could not initialize class com.jacob.com.ComThread
解决hbase client在windows环境下报Could not initialize class org.fusesource.jansi.internal.Kernel32的问题,把jar包放入hbase client的lib包下,重新运行hbase.cmd shell即可
Could not initialize "D:\app\Happy\product\11.2.0\dbhome_1\bin\oci.dll" Make sure you have the 32 bits Oracle Client installed. OracleHomeKey: OracleHomeDir: D:\app\Happy\product\11.2.0\dbhome_1 ...
java.lang.NoClassDefFoundError: Could not initialize class org.apache.derby.jdbc.AutoloadedDriver40 导致的原因: 在azkaban的server和executor中缺少一个叫derby.jar的包
在Linux操作系统上实现视频截图是一项常见的任务,尤其对于开发者来说,可能需要在处理多媒体内容时进行这样的操作。这里我们将深入探讨如何使用JavaCPP库在32位Linux环境下完成这一目标。 JavaCPP是一个强大的Java...
缺少这个包可能导致Could not initialize class net.sf.json.JsonConfig 使用json时候将会用到的一个jar包,发现这个包在网上提供的比较少.缺少这个包可能导致Could not initialize class net.sf.json.JsonConfig ...
解决:oracle_plsql连服务端时 Initialization error could initialize错误处理方法
JSONArray.fromObject(map)报错:Could not initialize class net.sf.json.JsonConfig。ireport 需要高于2.1版本的包。于是就找了这些包。最后2.2.2适合
报错如下: org.apache.catalina.startup.ContextConfig.beforeStart Exception fixing docBase for context [/test] java.util.zip.ZipException: error in opening zip file at java.util.zip.ZipFile.open...
在Java编程中,`ClassNotFoundException` 是一个常见的运行时异常,通常表示尝试加载某个类时,在类路径中找不到该类的定义。在这个特定的场景中,异常堆栈跟踪显示了 `Caused by: java.lang.ClassNotFoundException...
在Android开发过程中,有时会遇到一个常见的运行时异常——`java.lang.NoClassDefFoundError`。这个错误通常意味着在编译期间能够找到类的定义,但在运行时却无法加载该类。本文将深入探讨这个问题,特别是在Android...
com.github.virtuald:curvesapi:1.06 com.zaxxer:SparseBitSet:1.2 commons-codec:commons-codec:1.13 org.apache.commons:commons-collections4:4.4 org.apache.commons:commons-math3:3.6.1 org.apache.commons:...
MySQL数据库在启动时可能会遇到各种错误,其中一种常见的报错是"File ./mysql-bin.index not found (Errcode: 13)"。这个错误通常表明MySQL无法找到它的二进制日志索引文件(mysql-bin.index),并且错误代码13通常...
在Android平台上进行串口通信开发时,常常会遇到需要与硬件设备进行低级别交互的情况,例如读写传感器数据、控制外部设备等。标题中的“gnu.io.rar_android_gnu.io _librxtxSerial_librxtxSerial._librxtxS”提到了`...
在使用PL/SQL Developer这款强大的Oracle数据库管理工具时,有时可能会遇到“Could not initialize oci.dll”的错误提示,这通常是由于应用程序与Oracle客户端组件之间的兼容性问题导致的。本文将详细介绍如何解决这...
《Java媒体工具包(JAI)详解》 Java Media Framework (JMF) 和 Java Advanced Imaging (JAI) 是Java平台上处理多媒体数据的核心组件。本文将深入探讨JAI,特别是其核心库`javax.media.jai.jar`,以及与之相关的`...
背景: windows 7 64位操作系统,安装数据库:win64_11gR2_database_1of... Could not initialize C:oracleproduct10.2.0client_1inoci.dll Make sure you have the 32 bits Oracle Client installed. OCIDLL forc