-->
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.  [ 3 posts ] 
Author Message
 Post subject: Getting an error "Could not synchronize database state.."
PostPosted: Sat Oct 01, 2011 6:37 pm 
Newbie

Joined: Wed Sep 10, 2008 1:01 pm
Posts: 6
I am trying to write first project from hibernate.org documentation on EVENTS table. I am experiencing some issues with updating the database.
My EventManager which creates and stores the Event is like this:
Code:
    private void createAndStoreEvent(String title, Date theDate) {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();

        Event theEvent = new Event();
        theEvent.setTitle(title);
        theEvent.setDate(theDate);
        session.save(theEvent);

        session.getTransaction().commit();
    }


My Hibernate configuration is like this:
Code:
<session-factory>
    <property name="hibernate.connection.driver_class">sun.jdbc.odbc.JdbcOdbcDriver</property>
    <property name="hibernate.connection.url">jdbc:odbc:ds1</property>
    <property name="hibernate.connection.username">scott</property>
    <property name="hibernate.connection.password">***</property>
    <property name="hibernate.connection.autocommit">false</property>
    <property name="hibernate.connection.pool_size">1</property>
    <property name="hibernate.hbm2ddl.auto">create</property>
    <property name="hibernate.show_sql">true</property>
    <!-- Disable the second-level cache  -->
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
    <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
    <property name="hibernate.current_session_context_class">thread</property>
    <mapping resource="hibernate.hbm.xml"/>
  </session-factory>


Hibernate Mapping XML is like this:
Code:
<hibernate-mapping package="com.home.mavenproject1">
    <class name="Event" table="EVENTS" schema="SCOTT">
        <id name="id" column="EVENT_ID">
            <generator class="sequence">
                <param name="sequence">EVENTS_SEQ</param>
            </generator>
        </id>
        <property name="date" type="date" column="EVENT_DATE"/>
        <property name="title" type="string" column="TITLE"/>
    </class>
</hibernate-mapping>


Also, finally table is like this in DB:
Code:
SQL> desc events;
Name                                      Null?    Type
----------------------------------------- -------- ----------------------------
EVENT_ID                                  NOT NULL NUMBER(19)
EVENT_DATE                                         DATE
TITLE                                              VARCHAR2(255)

SQL>

I am getting the following exception. Can you please suggest a solution to rectify this error?
Code:
INFO: schema export complete
Hibernate: select EVENTS_SEQ.nextval from dual
Hibernate: insert into SCOTT.EVENTS (EVENT_DATE, TITLE, EVENT_ID) values (?, ?, ?)
Oct 1, 2011 5:24:00 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 0, SQLState: S1000
Oct 1, 2011 5:24:00 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: General error
Oct 1, 2011 5:24:00 PM org.hibernate.event.def.AbstractFlushingEventListener performExecutions
SEVERE: 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:126)
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
   at com.home.mavenproject1.Manager.EventManager.createAndStoreEvent(EventManager.java:42)
   at com.home.mavenproject1.Manager.EventManager.main(EventManager.java:24)
Caused by: sun.jdbc.odbc.JdbcOdbcBatchUpdateException: General error
   at sun.jdbc.odbc.JdbcOdbcPreparedStatement.emulateExecuteBatch(JdbcOdbcPreparedStatement.java:2165)
   at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeBatchUpdate(JdbcOdbcPreparedStatement.java:1783)
   at sun.jdbc.odbc.JdbcOdbcStatement.executeBatch(JdbcOdbcStatement.java:912)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
   ... 9 more
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
   at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
   at com.home.mavenproject1.Manager.EventManager.createAndStoreEvent(EventManager.java:42)
   at com.home.mavenproject1.Manager.EventManager.main(EventManager.java:24)
Caused by: sun.jdbc.odbc.JdbcOdbcBatchUpdateException: General error
   at sun.jdbc.odbc.JdbcOdbcPreparedStatement.emulateExecuteBatch(JdbcOdbcPreparedStatement.java:2165)
   at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeBatchUpdate(JdbcOdbcPreparedStatement.java:1783)
   at sun.jdbc.odbc.JdbcOdbcStatement.executeBatch(JdbcOdbcStatement.java:912)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
   ... 9 more
Oct 1, 2011 5:24:01 PM org.hibernate.impl.SessionFactoryImpl close
INFO: closing
Oct 1, 2011 5:24:01 PM org.hibernate.connection.DriverManagerConnectionProvider close
INFO: cleaning up connection pool: jdbc:odbc:ds1


Top
 Profile  
 
 Post subject: Re: Getting an error "Could not synchronize database state.."
PostPosted: Sun Oct 02, 2011 4:04 pm 
Newbie

Joined: Sun Sep 25, 2011 4:05 pm
Posts: 12
1. Did you manually build your database or let hibernate do it for you?
2. Have you tried with a fresh database? Meaning you either dropped and recreated the database, or pointed hibernate to a new one?
3. Can you show us the output of sql: "show create table events;" You might have to translate that to oracle, not sure.
4. Not sure, but I think the problem might be with your generator class sequence. I cannot find documentation that says "sequence" is a parameter of the "sequence" element. Maybe I'm mistaken, I always use "native" as my generator, so have no experience with that.
5. I think you showed us the console output, but not the hibernate logs. The hibernate logs should have details on the initialization of your database. Have you checked the hibernate logs for any exceptions, errors, warnings? The hibernate logs should be in the root of your project, or at least that's where mine show up by default.

Other advice: You should really follow the idioms for your session code. Wrap the code with a try-catch. put the transaction commit in the try, and the rollback in your catch. Not doing this will produce headaches. See these for examples:

http://community.jboss.org/wiki/SessionsAndTransactions

http://docs.jboss.org/hibernate/annotat ... lizable%29


Top
 Profile  
 
 Post subject: Re: Getting an error "Could not synchronize database state.."
PostPosted: Tue Oct 04, 2011 10:16 am 
Newbie

Joined: Wed Sep 10, 2008 1:01 pm
Posts: 6
1. I let hibernate build the tables.
2. I have tried with a fresh database with no tables from the hbm file.
3. The tables are not even created at this point.
4. Jboss hibernate reference shows sequence parameter for sequence. (sequence is written in oracle)
http://docs.jboss.org/hibernate/core/3. ... pings.html
5. I will post the hibernate logs (after going home tonight :-( )

Thanks for those links. I will try them as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.