日期:2014-05-20  浏览次数:20734 次

Hibernate多对多插入Oracle中,关联表的序列问题
我想在有两张表,然后我通过Hibernate的多对多的关系给他们建立关系,如:role角色表中有多个权限,一个权限对应多个角色,然后我建立了 关联表 role_right 里面有字段:rfid,rf_role_id,rf_right_code
关系插入的时候:rfid插入不了,hibernate没有发查询序列SQL语句,错误代码如下:很常见在网上
sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("SHARME"."SYS_ROLE_RIGHT"."RF_ID")

oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907)
org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
com.sharme.right.web.action.SysRoleAction.doAssignRights(SysRoleAction.java:261)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.sharme.recruitment.tools.FilterCloseSession.doFilter(FilterCloseSession.java:22)
com.sharme.recruitment.tools.FilterString.doFilter(FilterString.java:49)


------解决方案--------------------
配置文件。。关联属性如set中加一个cascade="save-update"或者cascade="all"
1. save-update只有持久化对象保存和更新操作,才会级联操作关联对象
2. all对持久化对象的所有操作都会级联操作关联对象(子)


------解决方案--------------------
rfid在应用中有无使用,没有使用建议把其删除掉,如果有使用需要建立中间表的实体....将你上面的分成两个one-to-many来做吧..