-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hilo table generator
PostPosted: Tue Aug 23, 2005 11:32 am 
Newbie

Joined: Tue Aug 23, 2005 11:14 am
Posts: 5
Location: London
Hi,

I have
Code:
<property name="hbm2ddl.auto">create</property>
turned on in my hibernate.cfg.xml file. The table generator doesn't generate what I expect for
Code:
<generator/>
elements of the various persisted classes.

For the mapping doucments listed below I would expect there to be three columns in the database for the
Code:
hibernate_seq
table (categoryid, itemid, and userid). However only categoryid is generated.

Any help would be appreciated. I have search the documentation and forums.

Thanks,
Michael

Hibernate version:
3.0.5

Mapping documents:

<class name="Category" table="category">
<id name="categoryId" column="categoryid">
<generator class="hilo">
<param name="table">hibernate_seq</param>
<param name="column">categoryid</param>
<param name="max_lo">10</param>
</generator>
</id>
...
</class>

<class name="Item" table="item">
<id name="itemId" column="itemid">
<generator class="hilo">
<param name="table">hibernate_seq</param>
<param name="column">itemid</param>
<param name="max_lo">10</param>
</generator>
</id>
...
</class>

<class name="User" table="user">
<id name="userId" column="userid">
<generator class="hilo">
<param name="table">hibernate_seq</param>
<param name="column">userid</param>
<param name="max_lo">10</param>
</generator>
</id>
...
</class>


Code between sessionFactory.openSession() and session.close():
N/A

Full stack trace of any exception that occurs:
org.hibernate.exception.SQLGrammarException: could not get or update next value
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.engine.TransactionHelper.doWorkInNewTransaction(TransactionHelper.java:85)
at org.hibernate.id.TableGenerator.generate(TableGenerator.java:94)
at org.hibernate.id.TableHiLoGenerator.generate(TableHiLoGenerator.java:61)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:85)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:481)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:476)
at com.idealoutcome.eauction.testing.HibernateTesting.main(HibernateTesting.java:36)
Caused by: java.sql.SQLException: Column not found message from server: "Unknown column 'categoryid' in 'field list'"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2247)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1586)
at org.hibernate.id.TableGenerator.doWorkInCurrentTransaction(TableGenerator.java:133)
at org.hibernate.engine.TransactionHelper.doWorkInNewTransaction(TransactionHelper.java:64)
... 11 more
Exception in thread "main"

Name and version of the database you are using:
MySQL 4.0.14-nt

The generated SQL (show_sql=true):


Debug level Hibernate log excerpt:

Code:


Top
 Profile  
 
 Post subject: Suggested fix
PostPosted: Thu Aug 25, 2005 4:57 am 
Newbie

Joined: Tue Aug 23, 2005 11:14 am
Posts: 5
Location: London
I believe I know what is happening now. The hbm2dll code used to genereate the schema isn't clever enough to work out that it should either wait for all identity properties to be parsed before creating hte table, or it can add columns to the sequence table for fear of breaking hte schema.

Looks like different tables will have to be used for each class if you are using <property name="hbm2dll.auto">create</property> in your hibernate.cfg.xml file.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 5:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Of course different tables should be used!

!!


Top
 Profile  
 
 Post subject: Use of different tables for identity hilo values
PostPosted: Thu Aug 25, 2005 6:54 am 
Newbie

Joined: Tue Aug 23, 2005 11:14 am
Posts: 5
Location: London
Having a seperate table for each HiLo value seems to be a bit strange.

If a table is to be used for storing a single value, then you shouldn't need the column attribute, if it is also to be used for other things, then it is restricted to a single row.

I have seen other tools using a different approach which you may want to consider (maybe you already support this). For each HiLo value needed you have a row in the sequence table where the primary key is a value specified in the mapping file, and another column holding the current value:


i.e
hibernate_seq
----------------------------------
'HiLo entity' 'Value'
Item 1
Category 12
User 5


Top
 Profile  
 
 Post subject: [Tablegenerator] & [hbm2ddl]
PostPosted: Mon Sep 04, 2006 11:57 am 
Newbie

Joined: Tue Feb 07, 2006 4:57 am
Posts: 1
Hi,
i need same help too.

I nedd use "hbm2ddl" and set my "<generator> like this:

=====================
[...]
<id name="azioneID" type="integer" column="AZI_ID">
<generator class="org.hibernate.id.TableGenerator">
<param name="table">tb_contatori_sql</param>
<param name="column">id_azione</param>
</generator>
</id>
[...]
=====================

(i have more one in my hibernate configuration file)

when i need generate tables in my DB i correctly find a table named "tb_contatori_sql" but inside the table i have only one filed for genarate ID.

Can you help me, please ?
Tks.


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