-->
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.  [ 14 posts ] 
Author Message
 Post subject: ID generator - White paper
PostPosted: Tue Oct 07, 2003 12:27 pm 
Beginner
Beginner

Joined: Tue Oct 07, 2003 12:11 pm
Posts: 32
Location: US
Is there a white paper that has the complete description of which ID generator could be used or/and that provides a case-by-case analysis of which ID generator could be used for a particular situation.

Is there a white paper of tech specification on how these ID generators are implemented by Hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2003 12:48 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
http://www.hibernate.org/hib_docs/reference/html/or-mapping.html#or-mapping-s1-4--generator

Note sure what you mean by "case-by-case". The names hibernate uses for these generators are pretty standard terms for key generation.


Top
 Profile  
 
 Post subject: ID generator
PostPosted: Wed Oct 08, 2003 1:05 pm 
Beginner
Beginner

Joined: Tue Oct 07, 2003 12:11 pm
Posts: 32
Location: US
Is there any thing like In-Memory sequence manager - That will improve the performance.

Only for the first time an uid request, we need to go to the database for the max value of the target column - all following request were performed in memory

Which document will tell me how the IDs are generated. (ie) Will Hibernate query the DB every time to get an ID or will it have some thing in memory.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 08, 2003 2:53 pm 
Beginner
Beginner

Joined: Fri Aug 29, 2003 12:38 am
Posts: 22
Location: Phoenix, AZ
It should be pretty easy to write such an id generator, but you risk problems if other programs/processes/vm's can alter the db. This would most definitely not work in a clustered environment unless you created a way to cluster the "current id in memory".

That being said, the HI/LO generator comes somewhere inbetween reading the db each time and storing exclusively in memory. Basically it grabs numbers a chunk at a time - so if different members of a cluster (different vm's) are running, they will each grab their own chunks, and can use them concurrently. Still a problem if you have outside programs writing to the tables, but they could also use the same hi/lo algorithim and get their seed value from the same table (default hibernate_unique_key)

If you are already concerned about the small performance gain of in-memory vs any existing plan, you definitely do not want to do something that eliminates the possibility of clustering!


Top
 Profile  
 
 Post subject: Re: ID generator
PostPosted: Sun Oct 12, 2003 5:57 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
Mukund wrote:
Is there any thing like In-Memory sequence manager - That will improve the performance.

Only for the first time an uid request, we need to go to the database for the max value of the target column - all following request were performed in memory

Which document will tell me how the IDs are generated. (ie) Will Hibernate query the DB every time to get an ID or will it have some thing in memory.


Have a look at http://www.hibernate.org/hib_docs/reference/html/or-mapping.html#or-mapping-s1-4, point 4.1.4.1

The increment does exactly what you describe.


Top
 Profile  
 
 Post subject: Is the reference enough?
PostPosted: Mon Nov 03, 2003 5:37 am 
Newbie

Joined: Mon Nov 03, 2003 5:19 am
Posts: 4
I've read the reference,but I still can not use the increment ID generator correctly,the exception is "expected type: int, actual value: java.lang.Long",when my hbm.xml is "<generator class="increment"/>".But I've succeed when use "<generator class="uuid.hex"/>".
So I wonder if the chapter of ID generator of the reference missed something important,is this true?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 03, 2003 5:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
If you are using Hibernate 2.0.3, try 2.1.


Top
 Profile  
 
 Post subject: Re: Is the reference enough?
PostPosted: Mon Nov 03, 2003 7:01 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
superbible wrote:
I've read the reference,but I still can not use the increment ID generator correctly,the exception is "expected type: int, actual value: java.lang.Long",when my hbm.xml is "<generator class="increment"/>".But I've succeed when use "<generator class="uuid.hex"/>".
So I wonder if the chapter of ID generator of the reference missed something important,is this true?


Here is part of my mapping file using the Increment generator:

Code:
      <!-- Unique Identifier -->
      <id name="uid" column="id" >
         <generator class="increment" />
      </id>


And in the corresponding Java class:

Code:
   /**
    * Holder for the unique Hibernate identifier
    */
   private Long uid;


Works without problem with Hibernate 2.1.* (2.0.* as well if I remember correctly).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 03, 2003 10:43 am 
Newbie

Joined: Mon Nov 03, 2003 5:19 am
Posts: 4
thank you!
I've succeed when changing the ID field from integer to long,that is:
"long id;" is ok,but "int id;" will be bad.
I find increment ID generator can work with int,short,long type in reference,but according above ,I can't use int typte and must use long type!So either It's a bug of hibernate or the reference do not describe clearly enough.
I still use hibernate 2.03,and I 'll try 2.1 later.


Top
 Profile  
 
 Post subject: still have problem
PostPosted: Tue Nov 04, 2003 5:26 am 
Newbie

Joined: Mon Nov 03, 2003 5:19 am
Posts: 4
I followed gavin's advice,and succeeded.
That is,using hibernate 2.1 will be ok.
But I found another problem,when I using "<generator class="increment"/>",I can run my program to insert record util the record
number reached 10.The ID generator cannot generates ID greater than 10?
The exception is:
Could not synchronize database state with session
net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:123)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2343)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2294)
at net.sf.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1791)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1475)
at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1499)
at net.sf.hibernate.impl.QueryImpl.iterate(QueryImpl.java:31)
at test.Servlet1.queryC(Servlet1.java:37)
at test.Servlet1.doGet(Servlet1.java:79)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:536)
Caused by: java.sql.BatchUpdateException: Invalid argument value: Duplicate entry '10' for key 1
at org.gjt.mm.mysql.jdbc2.PreparedStatement.executeBatch(Unknown Source)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:52)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:116)
... 20 more
net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:123)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2343)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2294)
at net.sf.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1791)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1475)
at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1499)
at net.sf.hibernate.impl.QueryImpl.iterate(QueryImpl.java:31)
at test.Servlet1.queryC(Servlet1.java:37)
at test.Servlet1.doGet(Servlet1.java:79)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:536)
Caused by: java.sql.BatchUpdateException: Invalid argument value: Duplicate entry '10' for key 1
at org.gjt.mm.mysql.jdbc2.PreparedStatement.executeBatch(Unknown Source)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:52)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:116)
... 20 more


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2003 6:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I think you are mistaken ;-) increment should work just fine, indefinately.


Top
 Profile  
 
 Post subject: Re: still have problem
PostPosted: Tue Nov 04, 2003 7:20 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
superbible wrote:
I followed gavin's advice,and succeeded.
That is,using hibernate 2.1 will be ok.
But I found another problem,when I using "<generator class="increment"/>",I can run my program to insert record util the record
number reached 10.The ID generator cannot generates ID greater than 10?


Maybe check your db schema - are you sure your ID field accepts values greater than 9 ?
Just a wild guess ;-)


Top
 Profile  
 
 Post subject: it's my fault
PostPosted: Tue Nov 04, 2003 8:46 am 
Newbie

Joined: Mon Nov 03, 2003 5:19 am
Posts: 4
At last ,it's really my fault.I set the ID field varchar type which should be int.Then the strange phenomenon appeared.
When I changed the field's type to int,everything run correctly.
Thank you !


Top
 Profile  
 
 Post subject: Re: it's my fault
PostPosted: Tue Nov 04, 2003 10:12 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
superbible wrote:
At last ,it's really my fault.I set the ID field varchar type which should be int.Then the strange phenomenon appeared.
When I changed the field's type to int,everything run correctly.
Thank you !


Why don't you let Hibernate generate the schema itself - you won't get such problem... ?


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