-->
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: generator increment is not working in my sample program
PostPosted: Wed Nov 20, 2013 4:23 am 
Newbie

Joined: Wed Nov 20, 2013 4:16 am
Posts: 4
Whenever I execute the Main.java file below I get this following error

"org.hibernate.exception.SQLGrammarException: could not fetch initial value for increment generator"

Main.java:


Code:
public class Main {
   
    public void createResonsibilities(){
          SessionFactory sessionfactory = NewHibernateUtil.getSessionFactory();
        Transaction transaction = null;
        try {
            Session session = sessionfactory.openSession();
            transaction = session.beginTransaction();         
            responsibilities responsibilityOne=new responsibilities("Java");
            responsibilities responsibilityTwo=new responsibilities("SQL");
            responsibilities responsibilityThree=new responsibilities("Oracle");
            session.save(responsibilityOne);
            session.save(responsibilityTwo);
            session.save(responsibilityThree);         
            transaction.commit();
        } catch (HibernateException e) {
            transaction.rollback();
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Main main=new Main();
        main.createResonsibilities();
       
}


My hibernate.cfg.xml has the property <property name="hibernate.hbm2ddl.auto">update</property>

So even though the table does not exist in the database it should get created I assume

This my complete error log

org.hibernate.exception.SQLGrammarException: could not fetch initial value for increment generator
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
Hibernate: select max(responsibilityId) from responsibilities
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.id.IncrementGenerator.initializePreviousValueHolder(IncrementGenerator.java:147)
at org.hibernate.id.IncrementGenerator.generate(IncrementGenerator.java:67)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:713)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:701)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:697)
at contacts.Main.createResonsibilities(Main.java:32)
at contacts.Main.main(Main.java:44)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'revision.responsibilities' doesn't exist

this is my responsibility.hbm.xml:

Code:
<hibernate-mapping>
  <class name="contacts.responsibilities" table="responsibilities">
    <meta attribute="class-description">
     
    </meta>
    <id column="responsibilityId" name="responsibilityId" type="long">
      <generator class="increment"/>
    </id>
    <property column="responsibilityName" name="responsibilityName" type="string"/>
  </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject: Re: generator increment is not working in my sample program
PostPosted: Wed Nov 20, 2013 6:22 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'revision.responsibilities' doesn't exist


As first step I would investigate about the origins of the word 'revisions' which seams to not appear in any mapping
reported here.


Top
 Profile  
 
 Post subject: Re: generator increment is not working in my sample program
PostPosted: Wed Nov 20, 2013 6:50 am 
Newbie

Joined: Wed Nov 20, 2013 4:16 am
Posts: 4
revision is the name of the database it is mentioned in the hibernate.cfg.xml
I only posted the code that generated the error and there is no need to mention the name of the database anywhere in the code that I have posted.


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.