-->
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.  [ 8 posts ] 
Author Message
 Post subject: This simple Hibernate doesn't work
PostPosted: Thu Oct 18, 2007 10:18 pm 
Newbie

Joined: Thu Oct 18, 2007 9:58 pm
Posts: 1
Hi there,
I m new to Hibernate, i got a problem while learning the Chapter 1 ... :(
http://www.hibernate.org/hib_docs/reference/en/html/tutorial.html#tutorial-firstapp

Here are the code that i wrote.

Hibernate version:3.2

Hibernate Configuration
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <!-- Database connection settings -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/hb_table</property>
        <property name="connection.username">root</property>
        <property name="connection.password"/>

        <property name="connection.pool_size">1</property>
        <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
        <property name="current_session_context_class">thread</property>
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <property name="show_sql">true</property>
        <property name="hbm2ddl.auto">create</property>
       
        <mapping resource="events/Event.hbm.xml"/>
    </session-factory>
</hibernate-configuration>



Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="events.Event" table="event">
        <id name="id" column="event_id">
            <generator class="native"/>
        </id>
        <property name="date" type="timestamp" column="event_date"/>
        <property name="title"/>
    </class>
</hibernate-mapping>




Code between sessionFactory.openSession() and session.close():
Code:
   private static void createAndStoreEvent(String title, Date date) {
      Session session = HibernateUtil.getSessionFactory().getCurrentSession();
      
      session.beginTransaction();
      
      Event event = new Event();
      event.setTitle(title);
      event.setDate(date);
      
      session.save(event);
      
      session.getTransaction().commit();
   }


Full stack trace of any exception that occurs:
Code:
run:
     [java] log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
     [java] log4j:WARN Please initialize the log4j system properly.
     [java] Hibernate: insert into event (event_id, event_date, title) values (null, ?, ?)
     [java] Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not insert: [events.Event]
     [java]     at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
     [java]     at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
     [java]     at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
     [java]     at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2158)
     [java]     at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2638)
     [java]     at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
     [java]     at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
     [java]     at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
     [java]     at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
     [java]     at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
     [java]     at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
     [java]     at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
     [java]     at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
     [java]     at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
     [java]     at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
     [java]     at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
     [java]     at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
     [java]     at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     [java]     at java.lang.reflect.Method.invoke(Method.java:585)
     [java]     at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
     [java]     at $Proxy0.save(Unknown Source)
     [java]     at events.EventManager.createAndStoreEvent(Unknown Source)
     [java]     at events.EventManager.main(Unknown Source)
     [java] Caused by: java.sql.SQLException: Table 'hb_table.event' doesn't exist
     [java]     at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2921)
     [java]     at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1570)
     [java]     at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
     [java]     at com.mysql.jdbc.Connection.execSQL(Connection.java:2978)
     [java]     at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)
     [java]     at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:930)
     [java]     at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1159)
     [java]     at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1076)
     [java]     at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1061)
     [java]     at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
     [java]     at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
     [java]     ... 23 more
     [java] Java Result: 1


Name and version of the database you are using:
MySQL - 5.0.22-Debian_0ubuntu6.06.3

The generated SQL (show_sql=true):
[java] Hibernate: insert into event (event_id, event_date, title) values (null, ?, ?)


Before running it, i created a database 'hb_table', which matches the database name in Hibernate configuration XML file.

But it looks that the table 'hb_event' can't be created when the program starts running, is it supposed to create the table automatically in Hibernate?

Is there anything wrong with my XML files? please help!

you help is sincerely appreciated!


Best regards


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 19, 2007 1:46 am 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
Yes it is supposed to create it because hbm2ddl.auto is set to create.

However since there's no log4j.properties, we can't see what's going wrong when hibernate tries to create the table.

Create a log4j.properties in your classpath so we can see the logs from hibernate.

Also doesn't MySQL have its own dialect? Is there a reason you are using HSQL dialect?

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 20, 2007 1:32 am 
Newbie

Joined: Sat Oct 20, 2007 1:25 am
Posts: 4
ignore this msg, please see the next.


Last edited by lytran on Sat Oct 20, 2007 1:36 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 20, 2007 1:33 am 
Newbie

Joined: Sat Oct 20, 2007 1:25 am
Posts: 4
I've gotten the same error by running straight from the sample code. Below is the log and thanks a lot for your help:


run:
[java] 22:19:46,203 INFO Environment:514 - Hibernate 3.2.5
[java] 22:19:46,203 INFO Environment:547 - hibernate.properties not found
[java] 22:19:46,203 INFO Environment:681 - Bytecode provider name : cglib
[java] 22:19:46,203 INFO Environment:598 - using JDK 1.4 java.sql.Timestam
p handling
[java] 22:19:46,250 INFO Configuration:1426 - configuring from resource: /
hibernate.cfg.xml
[java] 22:19:46,250 INFO Configuration:1403 - Configuration resource: /hib
ernate.cfg.xml
[java] 22:19:46,453 INFO Configuration:553 - Reading mappings from resourc
e : events/Event.hbm.xml
[java] 22:19:46,531 INFO HbmBinder:300 - Mapping class: events.Event -> EV
ENTS
[java] 22:19:46,562 INFO HbmBinder:1422 - Mapping collection: events.Event
.participants -> PERSON_EVENT
[java] 22:19:46,562 INFO Configuration:553 - Reading mappings from resourc
e : events/Person.hbm.xml
[java] 22:19:46,593 INFO HbmBinder:300 - Mapping class: events.Person -> P
ERSON
[java] 22:19:46,593 INFO HbmBinder:1422 - Mapping collection: events.Perso
n.events -> PERSON_EVENT
[java] 22:19:46,609 INFO HbmBinder:1422 - Mapping collection: events.Perso
n.emailAddresses -> PERSON_EMAIL_ADDR
[java] 22:19:46,609 INFO Configuration:1541 - Configured SessionFactory: n
ull
[java] 22:19:46,656 INFO DriverManagerConnectionProvider:41 - Using Hibern
ate built-in connection pool (not for production use!)
[java] 22:19:46,656 INFO DriverManagerConnectionProvider:42 - Hibernate co
nnection pool size: 1
[java] 22:19:46,656 INFO DriverManagerConnectionProvider:45 - autocommit m
ode: false
[java] 22:19:46,656 INFO DriverManagerConnectionProvider:80 - using driver
: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:hsql://localhost
[java] 22:19:46,656 INFO DriverManagerConnectionProvider:86 - connection p
roperties: {user=sa, password=****}
[java] 22:19:46,718 INFO SettingsFactory:89 - RDBMS: HSQL Database Engine,
version: 1.7.1
[java] 22:19:46,718 INFO SettingsFactory:90 - JDBC driver: HSQL Database E
ngine Driver, version: 1.7.1
[java] 22:19:46,734 INFO Dialect:152 - Using dialect: org.hibernate.dialec
t.HSQLDialect
[java] 22:19:46,750 INFO TransactionFactoryFactory:31 - Using default tran
saction strategy (direct JDBC transactions)
[java] 22:19:46,750 INFO TransactionManagerLookupFactory:33 - No Transacti
onManagerLookup configured (in JTA environment, use of read-write or transaction
al second-level cache is not recommended)
[java] 22:19:46,750 INFO SettingsFactory:143 - Automatic flush during befo
reCompletion(): disabled
[java] 22:19:46,750 INFO SettingsFactory:147 - Automatic session close at
end of transaction: disabled
[java] 22:19:46,750 INFO SettingsFactory:162 - Scrollable result sets: ena
bled
[java] 22:19:46,750 INFO SettingsFactory:170 - JDBC3 getGeneratedKeys(): d
isabled
[java] 22:19:46,765 INFO SettingsFactory:178 - Connection release mode: au
to
[java] 22:19:46,765 INFO SettingsFactory:205 - Default batch fetch size: 1

[java] 22:19:46,765 INFO SettingsFactory:209 - Generate SQL with comments:
disabled
[java] 22:19:46,765 INFO SettingsFactory:213 - Order SQL updates by primar
y key: disabled
[java] 22:19:46,765 INFO SettingsFactory:217 - Order SQL inserts for batch
ing: disabled
[java] 22:19:46,765 INFO SettingsFactory:386 - Query translator: org.hiber
nate.hql.ast.ASTQueryTranslatorFactory
[java] 22:19:46,765 INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTran
slatorFactory
[java] 22:19:46,765 INFO SettingsFactory:225 - Query language substitution
s: {}
[java] 22:19:46,765 INFO SettingsFactory:230 - JPA-QL strict compliance: d
isabled
[java] 22:19:46,765 INFO SettingsFactory:235 - Second-level cache: enabled

[java] 22:19:46,765 INFO SettingsFactory:239 - Query cache: disabled
[java] 22:19:46,765 INFO SettingsFactory:373 - Cache provider: org.hiberna
te.cache.NoCacheProvider
[java] 22:19:46,765 INFO SettingsFactory:254 - Optimize cache for minimal
puts: disabled
[java] 22:19:46,765 INFO SettingsFactory:263 - Structured second-level cac
he entries: disabled
[java] 22:19:46,765 INFO SettingsFactory:283 - Echoing all SQL to stdout
[java] 22:19:46,765 INFO SettingsFactory:290 - Statistics: disabled
[java] 22:19:46,765 INFO SettingsFactory:294 - Deleted entity synthetic id
entifier rollback: disabled
[java] 22:19:46,765 INFO SettingsFactory:309 - Default entity-mode: pojo
[java] 22:19:46,781 INFO SettingsFactory:313 - Named query checking : enab
led
[java] 22:19:46,796 INFO SessionFactoryImpl:161 - building session factory

[java] 22:19:47,031 INFO SessionFactoryObjectFactory:82 - Not binding fact
ory to JNDI, no JNDI name configured
[java] 22:19:47,031 INFO SchemaExport:154 - Running hbm2ddl schema export
[java] 22:19:47,031 DEBUG SchemaExport:170 - import file not found: /import
.sql
[java] 22:19:47,031 INFO SchemaExport:179 - exporting generated schema to
database
[java] 22:19:47,031 DEBUG SchemaExport:303 - alter table PERSON_EMAIL_ADDR
drop constraint FKA54215FE7708282F
[java] 22:19:47,046 DEBUG SchemaExport:288 - Unsuccessful: alter table PERS
ON_EMAIL_ADDR drop constraint FKA54215FE7708282F
[java] 22:19:47,046 DEBUG SchemaExport:289 - Table not found: PERSON_EMAIL_
ADDR in statement [alter table PERSON_EMAIL_ADDR drop constraint FKA54215FE77082
82F]
[java] 22:19:47,046 DEBUG SchemaExport:303 - alter table PERSON_EVENT drop
constraint FKAD91D9107708282F
[java] 22:19:47,046 DEBUG SchemaExport:288 - Unsuccessful: alter table PERS
ON_EVENT drop constraint FKAD91D9107708282F
[java] 22:19:47,046 DEBUG SchemaExport:289 - Table not found: PERSON_EVENT
in statement [alter table PERSON_EVENT drop constraint FKAD91D9107708282F]
[java] 22:19:47,046 DEBUG SchemaExport:303 - alter table PERSON_EVENT drop
constraint FKAD91D910F96D1A45
[java] 22:19:47,046 DEBUG SchemaExport:288 - Unsuccessful: alter table PERS
ON_EVENT drop constraint FKAD91D910F96D1A45
[java] 22:19:47,046 DEBUG SchemaExport:289 - Table not found: PERSON_EVENT
in statement [alter table PERSON_EVENT drop constraint FKAD91D910F96D1A45]
[java] 22:19:47,046 DEBUG SchemaExport:303 - drop table EVENTS if exists
[java] 22:19:47,046 DEBUG SchemaExport:303 - drop table PERSON if exists
[java] 22:19:47,046 DEBUG SchemaExport:303 - drop table PERSON_EMAIL_ADDR i
f exists
[java] 22:19:47,046 DEBUG SchemaExport:303 - drop table PERSON_EVENT if exi
sts
[java] 22:19:47,046 DEBUG SchemaExport:303 - create table EVENTS (EVENT_ID
bigint generated by default as identity (start with 1), EVENT_DATE timestamp, ti
tle varchar(255), primary key (EVENT_ID))
[java] 22:19:47,046 ERROR SchemaExport:274 - Unsuccessful: create table EVE
NTS (EVENT_ID bigint generated by default as identity (start with 1), EVENT_DATE
timestamp, title varchar(255), primary key (EVENT_ID))
[java] 22:19:47,046 ERROR SchemaExport:275 - Unexpected token: GENERATED in
statement [create table EVENTS (EVENT_ID bigint generated by default as identit
y (start with 1), EVENT_DATE timestamp, title varchar(255), primary key (EVENT_I
D))]
[java] 22:19:47,046 DEBUG SchemaExport:303 - create table PERSON (PERSON_ID
bigint generated by default as identity (start with 1), age integer, firstname
varchar(255), lastname varchar(255), primary key (PERSON_ID))
[java] 22:19:47,046 ERROR SchemaExport:274 - Unsuccessful: create table PER
SON (PERSON_ID bigint generated by default as identity (start with 1), age integ
er, firstname varchar(255), lastname varchar(255), primary key (PERSON_ID))
[java] 22:19:47,046 ERROR SchemaExport:275 - Unexpected token: GENERATED in
statement [create table PERSON (PERSON_ID bigint generated by default as identi
ty (start with 1), age integer, firstname varchar(255), lastname varchar(255), p
rimary key (PERSON_ID))]
[java] 22:19:47,046 DEBUG SchemaExport:303 - create table PERSON_EMAIL_ADDR
(PERSON_ID bigint not null, EMAIL_ADDR varchar(255))
[java] 22:19:47,062 DEBUG SchemaExport:303 - create table PERSON_EVENT (EVE
NT_ID bigint not null, PERSON_ID bigint not null, primary key (PERSON_ID, EVENT_
ID))
[java] 22:19:47,062 DEBUG SchemaExport:303 - alter table PERSON_EMAIL_ADDR
add constraint FKA54215FE7708282F foreign key (PERSON_ID) references PERSON
[java] 22:19:47,062 ERROR SchemaExport:274 - Unsuccessful: alter table PERS
ON_EMAIL_ADDR add constraint FKA54215FE7708282F foreign key (PERSON_ID) referenc
es PERSON
[java] 22:19:47,062 ERROR SchemaExport:275 - Table not found: PERSON in sta
tement [alter table PERSON_EMAIL_ADDR add constraint FKA54215FE7708282F foreign
key (PERSON_ID) references PERSON]
[java] 22:19:47,062 DEBUG SchemaExport:303 - alter table PERSON_EVENT add c
onstraint FKAD91D9107708282F foreign key (PERSON_ID) references PERSON
[java] 22:19:47,062 ERROR SchemaExport:274 - Unsuccessful: alter table PERS
ON_EVENT add constraint FKAD91D9107708282F foreign key (PERSON_ID) references PE
RSON
[java] 22:19:47,062 ERROR SchemaExport:275 - Table not found: PERSON in sta
tement [alter table PERSON_EVENT add constraint FKAD91D9107708282F foreign key (
PERSON_ID) references PERSON]
[java] 22:19:47,062 DEBUG SchemaExport:303 - alter table PERSON_EVENT add c
onstraint FKAD91D910F96D1A45 foreign key (EVENT_ID) references EVENTS
[java] 22:19:47,062 ERROR SchemaExport:274 - Unsuccessful: alter table PERS
ON_EVENT add constraint FKAD91D910F96D1A45 foreign key (EVENT_ID) references EVE
NTS
[java] 22:19:47,062 ERROR SchemaExport:275 - Table not found: EVENTS in sta
tement [alter table PERSON_EVENT add constraint FKAD91D910F96D1A45 foreign key (
EVENT_ID) references EVENTS]
[java] 22:19:47,062 INFO SchemaExport:196 - schema export complete
[java] Hibernate: insert into EVENTS (EVENT_ID, EVENT_DATE, title) values (
null, ?, ?)
[java] 22:19:47,265 WARN JDBCExceptionReporter:77 - SQL Error: -22, SQLSta
te: S0002
[java] 22:19:47,265 ERROR JDBCExceptionReporter:78 - Table not found: EVENT
S in statement [insert into EVENTS (EVENT_ID, EVENT_DATE, title) values (null, '
2007-10-19 22:19:46.109', 'My Event')]
[java] Exception in thread "main" org.hibernate.exception.SQLGrammarExcepti
on: could not insert: [events.Event]
[java] at org.hibernate.exception.SQLStateConverter.convert(SQLStateCon
verter.java:67)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExcep
tionHelper.java:43)
[java] at org.hibernate.id.insert.AbstractSelectingDelegate.performInse
rt(AbstractSelectingDelegate.java:40)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.insert
(AbstractEntityPersister.java:2158)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.insert
(AbstractEntityPersister.java:2638)
[java] at org.hibernate.action.EntityIdentityInsertAction.execute(Entit
yIdentityInsertAction.java:48)
[java] at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250
)
[java] at org.hibernate.event.def.AbstractSaveEventListener.performSave
OrReplicate(AbstractSaveEventListener.java:298)
[java] at org.hibernate.event.def.AbstractSaveEventListener.performSave
(AbstractSaveEventListener.java:181)
[java] at org.hibernate.event.def.AbstractSaveEventListener.saveWithGen
eratedId(AbstractSaveEventListener.java:107)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.save
WithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
[java] at org.hibernate.event.def.DefaultSaveEventListener.saveWithGene
ratedOrRequestedId(DefaultSaveEventListener.java:33)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.enti
tyIsTransient(DefaultSaveOrUpdateEventListener.java:172)
[java] at org.hibernate.event.def.DefaultSaveEventListener.performSaveO
rUpdate(DefaultSaveEventListener.java:27)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSa
veOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
[java] at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)

[java] at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
[java] at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcces
sorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMet
hodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:585)
[java] at org.hibernate.context.ThreadLocalSessionContext$TransactionPr
otectionWrapper.invoke(ThreadLocalSessionContext.java:301)
[java] at $Proxy0.save(Unknown Source)
[java] at events.EventManager.createAndStoreEvent(Unknown Source)
[java] at events.EventManager.main(Unknown Source)
[java] Caused by: java.sql.SQLException: Table not found: EVENTS in stateme
nt [insert into EVENTS (EVENT_ID, EVENT_DATE, title) values (null, '2007-10-19 2
2:19:46.109', 'My Event')]
[java] at org.hsqldb.Trace.getError(Unknown Source)
[java] at org.hsqldb.Result.<init>(Unknown Source)
[java] at org.hsqldb.jdbcConnection.executeHSQL(Unknown Source)
[java] at org.hsqldb.jdbcConnection.execute(Unknown Source)
[java] at org.hsqldb.jdbcStatement.fetchResult(Unknown Source)
[java] at org.hsqldb.jdbcStatement.executeUpdate(Unknown Source)
[java] at org.hsqldb.jdbcPreparedStatement.executeUpdate(Unknown Source
)
[java] at org.hibernate.id.insert.AbstractSelectingDelegate.performInse
rt(AbstractSelectingDelegate.java:33)
[java] ... 23 more
[java] HsqlStringBuffer init count: 0
[java] HsqlStringBuffer update count: 0
[java] HsqlStringBuffer append(char) count: 0
[java] HsqlStringBuffer append(String) count: 0
[java] HsqlStringBuffer waste count: 0
[java] HsqlStringBuffer toString count: 3
[java] HsqlArrayList init count: 1
[java] HsqlArrayList update count: 0
[java] HsqlHashMap init count: 3
[java] HsqlHashMap update count: 48
[java] 22:19:47,265 INFO DriverManagerConnectionProvider:147 - cleaning up
connection pool: jdbc:hsqldb:hsql://localhost
[java] Java Result: 1

BUILD SUCCESSFUL
Total time: 2 seconds
C:\eclipse\workspace\hibernate>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 20, 2007 1:51 am 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
So now we see that the table creation failed.

[java] 22:19:47,046 ERROR SchemaExport:274 - Unsuccessful: create table PERSON (PERSON_ID bigint generated by default as identity (start with 1), age integer, firstname varchar(255), lastname varchar(255), primary key (PERSON_ID))
[java] 22:19:47,046 ERROR SchemaExport:275 - Unexpected token: GENERATED in statement [create table PERSON (PERSON_ID bigint generated by default as identity (start with 1), age integer, firstname varchar(255), lastname varchar(255), primary key (PERSON_ID))]

Try changing
<property name="dialect">org.hibernate.dialect.HSQLDialect</property> in hibernate.cfg.xml

to

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

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 21, 2007 12:51 am 
Newbie

Joined: Sat Oct 20, 2007 1:25 am
Posts: 4
Thanks for your quick response. I've changed to mySQLDialect and didn'st seem to help, ie:

[java] 21:40:22,921 INFO Dialect:152 - Using dialect: org.hibernate.dialect.MySQLDialect


Below is the complete log:

BUILD SUCCESSFUL
Total time: 7 seconds
C:\eclipse\workspace\hibernate>ant run -Daction=store
Buildfile: build.xml

clean:
[delete] Deleting directory C:\eclipse\workspace\hibernate\bin
[mkdir] Created dir: C:\eclipse\workspace\hibernate\bin

copy-resources:
[copy] Copying 4 files to C:\eclipse\workspace\hibernate\bin
[copy] Copied 2 empty directories to 1 empty directory under C:\eclipse\wor
kspace\hibernate\bin

compile:
[javac] Compiling 5 source files to C:\eclipse\workspace\hibernate\bin
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.

run:
[java] 21:40:22,359 INFO Environment:514 - Hibernate 3.2.5
[java] 21:40:22,375 INFO Environment:547 - hibernate.properties not found
[java] 21:40:22,375 INFO Environment:681 - Bytecode provider name : cglib
[java] 21:40:22,375 INFO Environment:598 - using JDK 1.4 java.sql.Timestam
p handling
[java] 21:40:22,421 INFO Configuration:1426 - configuring from resource: /
hibernate.cfg.xml
[java] 21:40:22,421 INFO Configuration:1403 - Configuration resource: /hib
ernate.cfg.xml
[java] 21:40:22,625 INFO Configuration:553 - Reading mappings from resourc
e : events/Event.hbm.xml
[java] 21:40:22,703 INFO HbmBinder:300 - Mapping class: events.Event -> EV
ENTS
[java] 21:40:22,734 INFO HbmBinder:1422 - Mapping collection: events.Event
.participants -> PERSON_EVENT
[java] 21:40:22,734 INFO Configuration:553 - Reading mappings from resourc
e : events/Person.hbm.xml
[java] 21:40:22,765 INFO HbmBinder:300 - Mapping class: events.Person -> P
ERSON
[java] 21:40:22,765 INFO HbmBinder:1422 - Mapping collection: events.Perso
n.events -> PERSON_EVENT
[java] 21:40:22,765 INFO HbmBinder:1422 - Mapping collection: events.Perso
n.emailAddresses -> PERSON_EMAIL_ADDR
[java] 21:40:22,765 INFO Configuration:1541 - Configured SessionFactory: n
ull
[java] 21:40:22,828 INFO DriverManagerConnectionProvider:41 - Using Hibern
ate built-in connection pool (not for production use!)
[java] 21:40:22,828 INFO DriverManagerConnectionProvider:42 - Hibernate co
nnection pool size: 1
[java] 21:40:22,828 INFO DriverManagerConnectionProvider:45 - autocommit m
ode: false
[java] 21:40:22,828 INFO DriverManagerConnectionProvider:80 - using driver
: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:hsql://localhost
[java] 21:40:22,828 INFO DriverManagerConnectionProvider:86 - connection p
roperties: {user=sa, password=****}
[java] 21:40:22,906 INFO SettingsFactory:89 - RDBMS: HSQL Database Engine,
version: 1.7.1
[java] 21:40:22,906 INFO SettingsFactory:90 - JDBC driver: HSQL Database E
ngine Driver, version: 1.7.1
[java] 21:40:22,921 INFO Dialect:152 - Using dialect: org.hibernate.dialec
t.MySQLDialect
[java] 21:40:22,921 INFO TransactionFactoryFactory:31 - Using default tran
saction strategy (direct JDBC transactions)
[java] 21:40:22,937 INFO TransactionManagerLookupFactory:33 - No Transacti
onManagerLookup configured (in JTA environment, use of read-write or transaction
al second-level cache is not recommended)
[java] 21:40:22,937 INFO SettingsFactory:143 - Automatic flush during befo
reCompletion(): disabled
[java] 21:40:22,937 INFO SettingsFactory:147 - Automatic session close at
end of transaction: disabled
[java] 21:40:22,937 INFO SettingsFactory:162 - Scrollable result sets: ena
bled
[java] 21:40:22,937 INFO SettingsFactory:170 - JDBC3 getGeneratedKeys(): d
isabled
[java] 21:40:22,937 INFO SettingsFactory:178 - Connection release mode: au
to
[java] 21:40:22,937 INFO SettingsFactory:202 - Maximum outer join fetch de
pth: 2
[java] 21:40:22,937 INFO SettingsFactory:205 - Default batch fetch size: 1

[java] 21:40:22,937 INFO SettingsFactory:209 - Generate SQL with comments:
disabled
[java] 21:40:22,937 INFO SettingsFactory:213 - Order SQL updates by primar
y key: disabled
[java] 21:40:22,937 INFO SettingsFactory:217 - Order SQL inserts for batch
ing: disabled
[java] 21:40:22,937 INFO SettingsFactory:386 - Query translator: org.hiber
nate.hql.ast.ASTQueryTranslatorFactory
[java] 21:40:22,937 INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTran
slatorFactory
[java] 21:40:22,937 INFO SettingsFactory:225 - Query language substitution
s: {}
[java] 21:40:22,937 INFO SettingsFactory:230 - JPA-QL strict compliance: d
isabled
[java] 21:40:22,937 INFO SettingsFactory:235 - Second-level cache: enabled

[java] 21:40:22,937 INFO SettingsFactory:239 - Query cache: disabled
[java] 21:40:22,937 INFO SettingsFactory:373 - Cache provider: org.hiberna
te.cache.NoCacheProvider
[java] 21:40:22,937 INFO SettingsFactory:254 - Optimize cache for minimal
puts: disabled
[java] 21:40:22,937 INFO SettingsFactory:263 - Structured second-level cac
he entries: disabled
[java] 21:40:22,937 INFO SettingsFactory:283 - Echoing all SQL to stdout
[java] 21:40:22,937 INFO SettingsFactory:290 - Statistics: disabled
[java] 21:40:22,937 INFO SettingsFactory:294 - Deleted entity synthetic id
entifier rollback: disabled
[java] 21:40:22,937 INFO SettingsFactory:309 - Default entity-mode: pojo
[java] 21:40:22,937 INFO SettingsFactory:313 - Named query checking : enab
led
[java] 21:40:22,968 INFO SessionFactoryImpl:161 - building session factory

[java] 21:40:23,203 INFO SessionFactoryObjectFactory:82 - Not binding fact
ory to JNDI, no JNDI name configured
[java] 21:40:23,203 INFO SchemaExport:154 - Running hbm2ddl schema export
[java] 21:40:23,203 DEBUG SchemaExport:170 - import file not found: /import
.sql
[java] 21:40:23,203 INFO SchemaExport:179 - exporting generated schema to
database
[java] 21:40:23,203 DEBUG SchemaExport:303 - alter table PERSON_EMAIL_ADDR
drop foreign key FKA54215FE7708282F
[java] 21:40:23,203 DEBUG SchemaExport:288 - Unsuccessful: alter table PERS
ON_EMAIL_ADDR drop foreign key FKA54215FE7708282F
[java] 21:40:23,203 DEBUG SchemaExport:289 - Table not found: PERSON_EMAIL_
ADDR in statement [alter table PERSON_EMAIL_ADDR drop foreign key FKA54215FE7708
282F]
[java] 21:40:23,203 DEBUG SchemaExport:303 - alter table PERSON_EVENT drop
foreign key FKAD91D9107708282F
[java] 21:40:23,203 DEBUG SchemaExport:288 - Unsuccessful: alter table PERS
ON_EVENT drop foreign key FKAD91D9107708282F
[java] 21:40:23,203 DEBUG SchemaExport:289 - Table not found: PERSON_EVENT
in statement [alter table PERSON_EVENT drop foreign key FKAD91D9107708282F]
[java] 21:40:23,218 DEBUG SchemaExport:303 - alter table PERSON_EVENT drop
foreign key FKAD91D910F96D1A45
[java] 21:40:23,218 DEBUG SchemaExport:288 - Unsuccessful: alter table PERS
ON_EVENT drop foreign key FKAD91D910F96D1A45
[java] 21:40:23,218 DEBUG SchemaExport:289 - Table not found: PERSON_EVENT
in statement [alter table PERSON_EVENT drop foreign key FKAD91D910F96D1A45]
[java] 21:40:23,218 DEBUG SchemaExport:303 - drop table if exists EVENTS
[java] 21:40:23,218 DEBUG SchemaExport:288 - Unsuccessful: drop table if ex
ists EVENTS
[java] 21:40:23,218 DEBUG SchemaExport:289 - Table not found: IF in stateme
nt [drop table if exists EVENTS]
[java] 21:40:23,218 DEBUG SchemaExport:303 - drop table if exists PERSON
[java] 21:40:23,218 DEBUG SchemaExport:288 - Unsuccessful: drop table if ex
ists PERSON
[java] 21:40:23,218 DEBUG SchemaExport:289 - Table not found: IF in stateme
nt [drop table if exists PERSON]
[java] 21:40:23,218 DEBUG SchemaExport:303 - drop table if exists PERSON_EM
AIL_ADDR
[java] 21:40:23,218 DEBUG SchemaExport:288 - Unsuccessful: drop table if ex
ists PERSON_EMAIL_ADDR
[java] 21:40:23,218 DEBUG SchemaExport:289 - Table not found: IF in stateme
nt [drop table if exists PERSON_EMAIL_ADDR]
[java] 21:40:23,218 DEBUG SchemaExport:303 - drop table if exists PERSON_EV
ENT
[java] 21:40:23,218 DEBUG SchemaExport:288 - Unsuccessful: drop table if ex
ists PERSON_EVENT
[java] 21:40:23,218 DEBUG SchemaExport:289 - Table not found: IF in stateme
nt [drop table if exists PERSON_EVENT]
[java] 21:40:23,218 DEBUG SchemaExport:303 - create table EVENTS (EVENT_ID
bigint not null auto_increment, EVENT_DATE datetime, title varchar(255), primary
key (EVENT_ID))
[java] 21:40:23,218 ERROR SchemaExport:274 - Unsuccessful: create table EVE
NTS (EVENT_ID bigint not null auto_increment, EVENT_DATE datetime, title varchar
(255), primary key (EVENT_ID))
[java] 21:40:23,218 ERROR SchemaExport:275 - Unexpected token: AUTO_INCREME
NT in statement [create table EVENTS (EVENT_ID bigint not null auto_increment, E
VENT_DATE datetime, title varchar(255), primary key (EVENT_ID))]
[java] 21:40:23,218 DEBUG SchemaExport:303 - create table PERSON (PERSON_ID
bigint not null auto_increment, age integer, firstname varchar(255), lastname v
archar(255), primary key (PERSON_ID))
[java] 21:40:23,218 ERROR SchemaExport:274 - Unsuccessful: create table PER
SON (PERSON_ID bigint not null auto_increment, age integer, firstname varchar(25
5), lastname varchar(255), primary key (PERSON_ID))
[java] 21:40:23,218 ERROR SchemaExport:275 - Unexpected token: AUTO_INCREME
NT in statement [create table PERSON (PERSON_ID bigint not null auto_increment,
age integer, firstname varchar(255), lastname varchar(255), primary key (PERSON_
ID))]
[java] 21:40:23,218 DEBUG SchemaExport:303 - create table PERSON_EMAIL_ADDR
(PERSON_ID bigint not null, EMAIL_ADDR varchar(255))
[java] 21:40:23,234 DEBUG SchemaExport:303 - create table PERSON_EVENT (EVE
NT_ID bigint not null, PERSON_ID bigint not null, primary key (PERSON_ID, EVENT_
ID))
[java] 21:40:23,234 DEBUG SchemaExport:303 - alter table PERSON_EMAIL_ADDR
add index FKA54215FE7708282F (PERSON_ID), add constraint FKA54215FE7708282F fore
ign key (PERSON_ID) references PERSON (PERSON_ID)
[java] 21:40:23,234 ERROR SchemaExport:274 - Unsuccessful: alter table PERS
ON_EMAIL_ADDR add index FKA54215FE7708282F (PERSON_ID), add constraint FKA54215F
E7708282F foreign key (PERSON_ID) references PERSON (PERSON_ID)
[java] 21:40:23,234 ERROR SchemaExport:275 - Unexpected token: FKA54215FE77
08282F in statement [alter table PERSON_EMAIL_ADDR add index FKA54215FE7708282F
(PERSON_ID), add constraint FKA54215FE7708282F foreign key (PERSON_ID) reference
s PERSON (PERSON_ID)]
[java] 21:40:23,234 DEBUG SchemaExport:303 - alter table PERSON_EVENT add i
ndex FKAD91D9107708282F (PERSON_ID), add constraint FKAD91D9107708282F foreign k
ey (PERSON_ID) references PERSON (PERSON_ID)
[java] 21:40:23,234 ERROR SchemaExport:274 - Unsuccessful: alter table PERS
ON_EVENT add index FKAD91D9107708282F (PERSON_ID), add constraint FKAD91D9107708
282F foreign key (PERSON_ID) references PERSON (PERSON_ID)
[java] 21:40:23,234 ERROR SchemaExport:275 - Unexpected token: FKAD91D91077
08282F in statement [alter table PERSON_EVENT add index FKAD91D9107708282F (PERS
ON_ID), add constraint FKAD91D9107708282F foreign key (PERSON_ID) references PER
SON (PERSON_ID)]
[java] 21:40:23,234 DEBUG SchemaExport:303 - alter table PERSON_EVENT add i
ndex FKAD91D910F96D1A45 (EVENT_ID), add constraint FKAD91D910F96D1A45 foreign ke
y (EVENT_ID) references EVENTS (EVENT_ID)
[java] 21:40:23,234 ERROR SchemaExport:274 - Unsuccessful: alter table PERS
ON_EVENT add index FKAD91D910F96D1A45 (EVENT_ID), add constraint FKAD91D910F96D1
A45 foreign key (EVENT_ID) references EVENTS (EVENT_ID)
[java] 21:40:23,234 ERROR SchemaExport:275 - Unexpected token: FKAD91D910F9
6D1A45 in statement [alter table PERSON_EVENT add index FKAD91D910F96D1A45 (EVEN
T_ID), add constraint FKAD91D910F96D1A45 foreign key (EVENT_ID) references EVENT
S (EVENT_ID)]
[java] 21:40:23,234 INFO SchemaExport:196 - schema export complete
[java] Hibernate: insert into EVENTS (EVENT_DATE, title) values (?, ?)
[java] 21:40:23,437 WARN JDBCExceptionReporter:77 - SQL Error: -22, SQLSta
te: S0002
[java] 21:40:23,437 ERROR JDBCExceptionReporter:78 - Table not found: EVENT
S in statement [insert into EVENTS (EVENT_DATE, title) values ('2007-10-20 21:40
:22.265', 'My Event')]
[java] Exception in thread "main" org.hibernate.exception.SQLGrammarExcepti
on: could not insert: [events.Event]
[java] at org.hibernate.exception.SQLStateConverter.convert(SQLStateCon
verter.java:67)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExcep
tionHelper.java:43)
[java] at org.hibernate.id.insert.AbstractSelectingDelegate.performInse
rt(AbstractSelectingDelegate.java:40)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.insert
(AbstractEntityPersister.java:2158)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.insert
(AbstractEntityPersister.java:2638)
[java] at org.hibernate.action.EntityIdentityInsertAction.execute(Entit
yIdentityInsertAction.java:48)
[java] at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250
)
[java] at org.hibernate.event.def.AbstractSaveEventListener.performSave
OrReplicate(AbstractSaveEventListener.java:298)
[java] at org.hibernate.event.def.AbstractSaveEventListener.performSave
(AbstractSaveEventListener.java:181)
[java] at org.hibernate.event.def.AbstractSaveEventListener.saveWithGen
eratedId(AbstractSaveEventListener.java:107)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.save
WithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
[java] at org.hibernate.event.def.DefaultSaveEventListener.saveWithGene
ratedOrRequestedId(DefaultSaveEventListener.java:33)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.enti
tyIsTransient(DefaultSaveOrUpdateEventListener.java:172)
[java] at org.hibernate.event.def.DefaultSaveEventListener.performSaveO
rUpdate(DefaultSaveEventListener.java:27)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSa
veOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
[java] at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)

[java] at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
[java] at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcces
sorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMet
hodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:585)
[java] at org.hibernate.context.ThreadLocalSessionContext$TransactionPr
otectionWrapper.invoke(ThreadLocalSessionContext.java:301)
[java] at $Proxy0.save(Unknown Source)
[java] at events.EventManager.createAndStoreEvent(Unknown Source)
[java] at events.EventManager.main(Unknown Source)
[java] Caused by: java.sql.SQLException: Table not found: EVENTS in stateme
nt [insert into EVENTS (EVENT_DATE, title) values ('2007-10-20 21:40:22.265', 'M
y Event')]
[java] at org.hsqldb.Trace.getError(Unknown Source)
[java] at org.hsqldb.Result.<init>(Unknown Source)
[java] at org.hsqldb.jdbcConnection.executeHSQL(Unknown Source)
[java] at org.hsqldb.jdbcConnection.execute(Unknown Source)
[java] at org.hsqldb.jdbcStatement.fetchResult(Unknown Source)
[java] at org.hsqldb.jdbcStatement.executeUpdate(Unknown Source)
[java] at org.hsqldb.jdbcPreparedStatement.executeUpdate(Unknown Source
)
[java] at org.hibernate.id.insert.AbstractSelectingDelegate.performInse
rt(AbstractSelectingDelegate.java:33)
[java] ... 23 more
[java] HsqlStringBuffer init count: 0
[java] HsqlStringBuffer update count: 0
[java] HsqlStringBuffer append(char) count: 0
[java] HsqlStringBuffer append(String) count: 0
[java] HsqlStringBuffer waste count: 0
[java] HsqlStringBuffer toString count: 3
[java] HsqlArrayList init count: 1
[java] HsqlArrayList update count: 0
[java] HsqlHashMap init count: 3
[java] HsqlHashMap update count: 48
[java] 21:40:23,437 INFO DriverManagerConnectionProvider:147 - cleaning up
connection pool: jdbc:hsqldb:hsql://localhost
[java] Java Result: 1

BUILD SUCCESSFUL
Total time: 2 seconds
C:\eclipse\workspace\hibernate>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 21, 2007 10:46 pm 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
Try changing
<generator class="native"/> to uuid.

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 30, 2007 3:44 pm 
Newbie

Joined: Sat Oct 20, 2007 1:25 am
Posts: 4
Hi Budyanto,

Ok in my case reverse url to hsqldb since I'm not using mySQL, change class to uuid and modify event.java to change from Long to String for event id, the tutor works wonderfully!!!

Thanks VERY much for your helps,

Lynn


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