-->
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.  [ 6 posts ] 
Author Message
 Post subject: Problems running Hello World example from the book
PostPosted: Thu Mar 05, 2009 11:26 pm 
Newbie

Joined: Thu Mar 05, 2009 11:18 pm
Posts: 1
Hey folks. I'm working through the Hello World app in the book and can't seem to get it to run, due to this error on the id of the Messages table.
Code:
mark@markUbuntu:~$ cd workspace/He*
mark@markUbuntu:~/workspace/HelloWorld$ ant run
Buildfile: build.xml

clean:
   [delete] Deleting directory /home/mark/workspace/HelloWorld/bin
    [mkdir] Created dir: /home/mark/workspace/HelloWorld/bin

compile:
    [javac] Compiling 3 source files to /home/mark/workspace/HelloWorld/bin

copymetafiles:
     [copy] Copying 3 files to /home/mark/workspace/HelloWorld/bin

run:
     [java] 21:07:49,99021:07:49,99521:07:50,00021:07:50,00421:07:50,06621:07:50,06621:07:50,17321:07:50,30021:07:50,38521:07:50,39721:07:50,39821:07:50,39821:07:50,40621:07:50,40621:07:50,70221:07:50,70221:07:50,71821:07:50,72321:07:50,72521:07:50,72521:07:50,72521:07:50,72521:07:50,72521:07:50,72621:07:50,72621:07:50,72621:07:50,72721:07:50,72721:07:50,72721:07:50,72721:07:50,72721:07:50,72721:07:50,72921:07:50,72921:07:50,72921:07:50,72921:07:50,72921:07:50,72921:07:50,73021:07:50,73021:07:50,73521:07:50,73621:07:50,73621:07:50,73621:07:50,73621:07:50,78121:07:51,011Hibernate:
     [java]     select
     [java]         max(MESSAGE_ID)
     [java]     from
     [java]         MESSAGES
     [java] Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not fetch initial value for increment generator
     [java]    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
     [java]    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
     [java]    at org.hibernate.id.IncrementGenerator.getNext(IncrementGenerator.java:131)
     [java]    at org.hibernate.id.IncrementGenerator.generate(IncrementGenerator.java:68)
     [java]    at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:122)
     [java]    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
     [java]    at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
     [java]    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
     [java]    at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
     [java]    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
     [java]    at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:562)
     [java]    at org.hibernate.impl.SessionImpl.save(SessionImpl.java:550)
     [java]    at org.hibernate.impl.SessionImpl.save(SessionImpl.java:546)
     [java]    at hello.HelloWorld.main(Unknown Source)
     [java] Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'HelloWorld.MESSAGES' doesn't exist
     [java]    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     [java]    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
     [java]    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
     [java]    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
     [java]    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
     [java]    at com.mysql.jdbc.Util.getInstance(Util.java:381)
     [java]    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
     [java]    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
     [java]    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)
     [java]    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)
     [java]    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
     [java]    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
     [java]    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2554)
     [java]    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1761)
     [java]    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1912)
     [java]    at org.hibernate.id.IncrementGenerator.getNext(IncrementGenerator.java:109)
     [java]    ... 11 more
     [java] 21:07:51,11721:07:51,117
     [java] Java Result: 1

BUILD SUCCESSFUL
Total time: 2 seconds
mark@markUbuntu:~/workspace/HelloWorld$


Hibernate version: 3

Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class
        name="hello.Message"
        table="MESSAGES">

        <id
            name="id"
            column="MESSAGE_ID">
       <generator class="increment"/>
        </id>

        <property
            name="text"
            column="MESSAGE_TEXT"/>

        <many-to-one
            name="nextMessage"
            cascade="all"
            column="NEXT_MESSAGE_ID"
            foreign-key="FK_NEXT_MESSAGE"/>
           

    </class>

</hibernate-mapping>


Name and version of the database you are using: MySQL 5.0

Any help would be appreciated!
Mark


Top
 Profile  
 
 Post subject: Re: Problems running Hello World example from the book
PostPosted: Thu Oct 29, 2009 5:41 pm 
Newbie

Joined: Thu Oct 29, 2009 5:25 pm
Posts: 2
I am having the same issue too. I dont know if I am getting anywhere with the solution, but when I change the generation to "native" inside the mapping xml file for message it gives a different error stating:

Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not insert: [hello.Message]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:40)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2093)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2573)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:47)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:180)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at hello.HelloWorld.main(HelloWorld.java:18)
Caused by: java.sql.SQLException: Table not found in statement [/* insert hello.Message */ insert into MESSAGES (MESSAGE_ID, MESSAGE_TEXT, NEXT_MESSAGE_ID) values (null, ?, ?)]
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
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 com.mchange.v2.c3p0.stmt.GooGooStatementCache$3.run(GooGooStatementCache.java:445)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:368)
Hibernate:
/* insert hello.Message
*/ insert
into
MESSAGES
(MESSAGE_ID, MESSAGE_TEXT, NEXT_MESSAGE_ID)
values
(null, ?, ?)
17:18:34,843 WARN JDBCExceptionReporter:71 - SQL Error: -22, SQLState: S0002
17:18:34,843 ERROR JDBCExceptionReporter:72 - Table not found in statement [/* insert hello.Message */ insert into MESSAGES (MESSAGE_ID, MESSAGE_TEXT, NEXT_MESSAGE_ID) values (null, ?, ?)]


However, if you look where it tries to insert a null value inside of a primary key ID.


Top
 Profile  
 
 Post subject: Re: Problems running Hello World example from the book
PostPosted: Thu Dec 10, 2009 8:21 am 
Newbie

Joined: Fri Dec 04, 2009 5:52 am
Posts: 9
Jyeshta Here..

I could not see POJO there. So my guess could be helpful for u:

1) In JavaBean check the datatype where u have speified MESSAGE_ID
2) Check it with database. MESSAGE_ID may be string.

I am sure it s problem with column MESSAGE_ID


Top
 Profile  
 
 Post subject: Re: Problems running Hello World example from the book
PostPosted: Fri Dec 11, 2009 8:15 am 
Newbie

Joined: Thu Dec 10, 2009 5:37 am
Posts: 3
I feel their is a problem in mapping file. It must use the bean properties instead of column names.
Try this, it may help.


Top
 Profile  
 
 Post subject: Re: Problems running Hello World example from the book
PostPosted: Fri Jan 01, 2010 8:41 am 
Newbie

Joined: Fri Jan 01, 2010 8:34 am
Posts: 2
Seems like I doing something dumb - I could not get this example working on MySQl. Well, I could not connect to the database itself!
I am running getting started example's helloworld-native. This runs perfectly fine on HSQL DB. I have modified hibernate configuration to accommodate MySQL. Here are the changes:

<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql:3306//localhost/test</property>

<property name="dialect">org.hibernate.dialect.MySQLDialect</property>


The exception thrown is (obvious):

[java] 18:10:10,147 WARN BasicResourcePool:1222 - com.mchange.v2.resourcep
ool.BasicResourcePool$AcquireTask@5329c5 -- Acquisition Attempt Failed!!! Cleari
ng pending acquires. While trying to acquire a needed new resource, we failed to
succeed more than the maximum number of allowed acquisition attempts (30).
[java] 18:10:10,154 WARN SettingsFactory:109 - Could not obtain connection
metadata
[java] java.sql.SQLException: Connections could not be acquired from the un
derlying database!
[java] at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:104)

Please correct me.
--Thanks


Top
 Profile  
 
 Post subject: Re: Problems running Hello World example from the book
PostPosted: Fri Jan 01, 2010 9:26 am 
Newbie

Joined: Fri Jan 01, 2010 8:34 am
Posts: 2
Oops. That was a silly mistake in the configuration. I could not notice an additional space in " hibernate.connection.password" property.
Please disregard the post.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.