1

I use hibernate to generate ids for my MySQL data-tables:

<class name="XXXX" table="XXXX">
    <id name="Id" column="Id" type="string">
        <generator class="guid"/>
    </id>
....
</class>

it works fine.

however, when i profiling the sql queried, there are 2 sqls for 1 insert:

1).select uuid() and then 2).insert ....

I have 3 questions:

  1. why not hibernate generates the "GUID"s locally?
  2. how much is the overhead for "select uuid()" than "UUID.randomUUID()" for one insert?
  3. can i config a "local" generator in hibernate?

1 Answer 1

2

AFAIK the GUID generator is deprecated and you should use the new(er) UUIDGenerator instead. See http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/mapping.html#d0e5294.

But to answer your questions

  1. That is how the GUID generator functions it calls the database and the result is passed into the id field of the object
  2. No idea, measure, however I guess the impact is negligible as the only thing you do additionally is return a simply value
  3. Yes but why as it is already supported by Hibernate (see the documentation)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.