-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Two problems with ORACLE
PostPosted: Mon Nov 27, 2006 6:15 am 
Newbie

Joined: Thu Aug 17, 2006 8:59 am
Posts: 7
Hibernate version: 3.1

Hi. I mapped id like this:


Code:
<class name="Sediste" table="sediste">
<id name="id" column="id" type="integer" unsaved-value="null">
            <generator class="sequence">
                 <param name="sequence">Sediste_id_SEQ</param>
            </generator>
        </id>
...


where Sediste_id_SEQ is ORACLE sequence. I also created trigger in database:
Code:
create or replace TRIGGER SET_Sediste_id
BEFORE INSERT
ON Sediste
FOR EACH ROW
BEGIN
  SELECT Sediste_id_SEQ.NEXTVAL
  INTO :NEW.id
  FROM DUAL;
END;

After inserting some row in table Sediste inserted data has id = 43 but persistence object has id = 44 after inserting. Why is that? If I disable trigger everything is working fine, but I want do that? How can I solve this problem?

Second problem is, that occasionally I get following error:
Code:
2006-11-27 10:42:51,546 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 8177, SQLState: 72000
2006-11-27 10:42:51,546 ERROR [org.hibernate.util.JDBCExceptionReporter] - ORA-08177: can't serialize access for this transaction

2006-11-27 10:42:51,546 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 8177, SQLState: 72000
2006-11-27 10:42:51,546 ERROR [org.hibernate.util.JDBCExceptionReporter] - ORA-08177: can't serialize access for this transaction

2006-11-27 10:42:51,562 ERROR [org.hibernate.event.def.AbstractFlushingEventListener] - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
   at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
   at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:558)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:540)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:510)
   at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:310)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:117)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:209)
   at $Proxy1.updateDocument(Unknown Source)
   at yu.gov.sr.poreskauprava.rpo.web.action.RegistracijaAction.markAsViewed(RegistracijaAction.java:85)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.springframework.webflow.util.DispatchMethodInvoker.invoke(DispatchMethodInvoker.java:105)
   at org.springframework.webflow.action.MultiAction.doExecute(MultiAction.java:136)
   at org.springframework.webflow.action.AbstractAction.execute(AbstractAction.java:203)
   at org.springframework.webflow.engine.AnnotatedAction.execute(AnnotatedAction.java:142)
   at org.springframework.webflow.engine.ActionExecutor.execute(ActionExecutor.java:61)
   at org.springframework.webflow.engine.ActionList.execute(ActionList.java:160)
   at org.springframework.webflow.engine.State.enter(State.java:199)
   at org.springframework.webflow.engine.Transition.execute(Transition.java:218)
   at org.springframework.webflow.engine.TransitionableState.onEvent(TransitionableState.java:112)
   at org.springframework.webflow.engine.Flow.onEvent(Flow.java:572)
   at org.springframework.webflow.engine.impl.RequestControlContextImpl.signalEvent(RequestControlContextImpl.java:207)
   at org.springframework.webflow.engine.ActionState.doEnter(ActionState.java:185)
   at org.springframework.webflow.engine.State.enter(State.java:200)
   at org.springframework.webflow.engine.Flow.start(Flow.java:557)
   at org.springframework.webflow.engine.impl.RequestControlContextImpl.start(RequestControlContextImpl.java:195)
   at org.springframework.webflow.engine.SubflowState.doEnter(SubflowState.java:120)
   at org.springframework.webflow.engine.State.enter(State.java:200)
   at org.springframework.webflow.engine.Transition.execute(Transition.java:218)
   at org.springframework.webflow.engine.DecisionState.doEnter(DecisionState.java:58)
   at org.springframework.webflow.engine.State.enter(State.java:200)
   at org.springframework.webflow.engine.Transition.execute(Transition.java:218)
   at org.springframework.webflow.engine.DecisionState.doEnter(DecisionState.java:58)
   at org.springframework.webflow.engine.State.enter(State.java:200)
   at org.springframework.webflow.engine.Transition.execute(Transition.java:218)
   at org.springframework.webflow.engine.TransitionableState.onEvent(TransitionableState.java:112)
   at org.springframework.webflow.engine.Flow.onEvent(Flow.java:572)
   at org.springframework.webflow.engine.impl.RequestControlContextImpl.signalEvent(RequestControlContextImpl.java:207)
   at org.springframework.webflow.engine.ActionState.doEnter(ActionState.java:185)
   at org.springframework.webflow.engine.State.enter(State.java:200)
   at org.springframework.webflow.engine.Flow.start(Flow.java:557)
   at org.springframework.webflow.engine.impl.RequestControlContextImpl.start(RequestControlContextImpl.java:195)
   at org.springframework.webflow.engine.SubflowState.doEnter(SubflowState.java:120)
   at org.springframework.webflow.engine.State.enter(State.java:200)
   at org.springframework.webflow.engine.Transition.execute(Transition.java:218)
   at org.springframework.webflow.engine.TransitionableState.onEvent(TransitionableState.java:112)
   at org.springframework.webflow.engine.Flow.onEvent(Flow.java:572)
   at org.springframework.webflow.engine.impl.RequestControlContextImpl.signalEvent(RequestControlContextImpl.java:207)
   at org.springframework.webflow.engine.impl.FlowExecutionImpl.signalEvent(FlowExecutionImpl.java:211)
   at org.springframework.webflow.executor.FlowExecutorImpl.resume(FlowExecutorImpl.java:227)
   at org.springframework.webflow.executor.support.FlowRequestHandler.handleFlowRequest(FlowRequestHandler.java:115)
   at org.springframework.webflow.executor.mvc.FlowController.handleRequestInternal(FlowController.java:170)
   at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
   at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:45)
   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:806)
   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:736)
   at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:396)
   at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:350)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:78)
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
   at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:138)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
   at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
   at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
   at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.BatchUpdateException: ORA-08177: can't serialize access for this transaction

   at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:367)
   at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:9119)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
   ... 88 more
2006-11-27 10:42:51,578 ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/registar].[registarPO]] - Servlet.service() for servlet registarPO threw exception
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
   at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
   at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:558)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:540)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:510)
   at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:310)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:117)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:209)
   at $Proxy1.updateDocument(Unknown Source)
   at yu.gov.sr.poreskauprava.rpo.web.action.RegistracijaAction.markAsViewed(RegistracijaAction.java:85)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.springframework.webflow.util.DispatchMethodInvoker.invoke(DispatchMethodInvoker.java:105)
   at org.springframework.webflow.action.MultiAction.doExecute(MultiAction.java:136)
   at org.springframework.webflow.action.AbstractAction.execute(AbstractAction.java:203)
   at org.springframework.webflow.engine.AnnotatedAction.execute(AnnotatedAction.java:142)
   at org.springframework.webflow.engine.ActionExecutor.execute(ActionExecutor.java:61)
   at org.springframework.webflow.engine.ActionList.execute(ActionList.java:160)
   at org.springframework.webflow.engine.State.enter(State.java:199)
   at org.springframework.webflow.engine.Transition.execute(Transition.java:218)
   at org.springframework.webflow.engine.TransitionableState.onEvent(TransitionableState.java:112)
   at org.springframework.webflow.engine.Flow.onEvent(Flow.java:572)
   at org.springframework.webflow.engine.impl.RequestControlContextImpl.signalEvent(RequestControlContextImpl.java:207)
   at org.springframework.webflow.engine.ActionState.doEnter(ActionState.java:185)
   at org.springframework.webflow.engine.State.enter(State.java:200)
   at org.springframework.webflow.engine.Flow.start(Flow.java:557)
   at org.springframework.webflow.engine.impl.RequestControlContextImpl.start(RequestControlContextImpl.java:195)
   at org.springframework.webflow.engine.SubflowState.doEnter(SubflowState.java:120)
   at org.springframework.webflow.engine.State.enter(State.java:200)
   at org.springframework.webflow.engine.Transition.execute(Transition.java:218)
   at org.springframework.webflow.engine.DecisionState.doEnter(DecisionState.java:58)
   at org.springframework.webflow.engine.State.enter(State.java:200)
   at org.springframework.webflow.engine.Transition.execute(Transition.java:218)
   at org.springframework.webflow.engine.DecisionState.doEnter(DecisionState.java:58)
   at org.springframework.webflow.engine.State.enter(State.java:200)
   at org.springframework.webflow.engine.Transition.execute(Transition.java:218)
   at org.springframework.webflow.engine.TransitionableState.onEvent(TransitionableState.java:112)
   at org.springframework.webflow.engine.Flow.onEvent(Flow.java:572)
   at org.springframework.webflow.engine.impl.RequestControlContextImpl.signalEvent(RequestControlContextImpl.java:207)
   at org.springframework.webflow.engine.ActionState.doEnter(ActionState.java:185)
   at org.springframework.webflow.engine.State.enter(State.java:200)
   at org.springframework.webflow.engine.Flow.start(Flow.java:557)
   at org.springframework.webflow.engine.impl.RequestControlContextImpl.start(RequestControlContextImpl.java:195)
   at org.springframework.webflow.engine.SubflowState.doEnter(SubflowState.java:120)
   at org.springframework.webflow.engine.State.enter(State.java:200)
   at org.springframework.webflow.engine.Transition.execute(Transition.java:218)
   at org.springframework.webflow.engine.TransitionableState.onEvent(TransitionableState.java:112)
   at org.springframework.webflow.engine.Flow.onEvent(Flow.java:572)
   at org.springframework.webflow.engine.impl.RequestControlContextImpl.signalEvent(RequestControlContextImpl.java:207)
   at org.springframework.webflow.engine.impl.FlowExecutionImpl.signalEvent(FlowExecutionImpl.java:211)
   at org.springframework.webflow.executor.FlowExecutorImpl.resume(FlowExecutorImpl.java:227)
   at org.springframework.webflow.executor.support.FlowRequestHandler.handleFlowRequest(FlowRequestHandler.java:115)
   at org.springframework.webflow.executor.mvc.FlowController.handleRequestInternal(FlowController.java:170)
   at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
   at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:45)
   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:806)
   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:736)
   at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:396)
   at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:350)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:78)
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
   at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:138)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
   at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
   at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
   at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.BatchUpdateException: ORA-08177: can't serialize access for this transaction

   at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:367)
   at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:9119)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
   ... 88 more


Any help is appreciated. Thanks.

Regards.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 27, 2006 7:18 am 
Regular
Regular

Joined: Sat May 20, 2006 3:49 am
Posts: 78
First you should knwo how you would like to fill the Id column:

- by Hibernate which calls the sequence and fills the Id-column
- by Oracle, which executes the trigger before a record is inserted

I think you don't need an Oracle Trigger, since Hibernate can fill the Id with a sequence from your database.

For example, I use:
Code:
    @GenericGenerator(name = "generator", strategy = "guid", parameters = {})
    @Id


I think your problem is, that you fetch an ID from the sequence twice, once with Hibernate and once again with your Trigger.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 27, 2006 8:20 am 
Newbie

Joined: Thu Aug 17, 2006 8:59 am
Posts: 7
Thanks for reply, that works, but how can I map id in order to let ORACLE manage incrementing of it, not Hibernate?

Second error that I'm getting is very annoying.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 4:46 pm 
Newbie

Joined: Wed Dec 06, 2006 4:04 pm
Posts: 8
Location: New Hampshire
Hi
This is how I am doing it:

Trigger:
CREATE OR REPLACE TRIGGER CHATITEM_BRI
BEFORE INSERT
ON CHATITEM
FOR EACH ROW
BEGIN
IF :new.CHAT_ITEM_ID IS NULL THEN
SELECT CHATITEM_seq.nextval
INTO :new.CHAT_ITEM_ID
FROM dual;
END IF;
END;

Then I use the following annotations on the id field:

@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="CHATITEM_SEQ_GEN")
@SequenceGenerator(name="CHATITEM_SEQ_GEN", sequenceName="CHATITEM_SEQ",initialValue=1,allocationSize=1)
@Column(name = "CHAT_ITEM_ID", insertable= false, updatable = false)

This is working for me.
J


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.