Educating the world

Our blog has over 10,000 readers a month

« Stripping line feeds from dos filesHow can I do lazy loading with a one-to-one relationship in hibernate? »


Comment from: Stephane [Visitor]

La solution que tu donnes correspond parfaitement à mon problème. Je l’ai donc suivie scrupuleusement. Mais j’ai une erreur qui est générée suite à l’utilisation de l’UUID:
[MrN: The solution you give fits to my problem. So I followed scrupulously. But I get an error that is generated as a result of using the UUID]

org.springframework.dao.InvalidDataAccessResourceUsageException: Could not execute JDBC batch update; nested exception is org.hibernate.exception.DataException: Could not execute JDBC batch update

Quelqu’un peut-il m’aider ?
[MrN: Can anyone help me?]
Merci d’avance

05/02/09 @ 16:36
Comment from: davidnewcomb [Member]  

You must make sure that the foreign key you are linking to is also set to be a UUID.

You are probably getting the exception because hibernate is trying to insert a record with no id, then trying to update it afterwards with a newly generated key.

Without seeing your code it’s difficult to tell.

I remember getting this exception and used the Eclipse debugger to figure it out, then changed my configuration accordingly.

05/02/09 @ 17:14
Comment from: Aaron [Visitor]

Thanks for the tutorial. This is great information.

I followed your instructions exactly and am getting the following error:

Initial SessionFactory creation Could not determine type for: bsuuid, for columns: [org.hibernate.mapping.Column(id)]

Any ideas? Thanks.

11/02/09 @ 00:16
Comment from: Jason Bennett [Visitor]
Jason Bennett

Thanks very much for your work on the UUID generator and user type. I was looking over to code to incorporate it into my project, and had a few questions about the user type implementation.

In deepCopy, since the UUID is immutable, I don’t believe you need to do any work - just return the value passed in.

For assemble and disassemble and replace, since UUIDs are serializable, is there any need to convert to String?

Under equals(), I don’t believe you need to cast before calling equals. You should just be able to check == and then call .equals().

Hashcode can probably just return hashcode(); I think the casting check is somewhat superfluous.

If your understanding is different from mine, please let me know. I have some UserType experience, but not a ton.


21/01/10 @ 10:33
Comment from: davidnewcomb [Member]  

deepCopy - I agree.

serializable - UUID has a readObject() but no writeObject(). If you don’t explicitly assemble them then you get an exception when talking to the database because the (automatic) serialisation done by Java becomes the actual bytes in memory of the UUID which are invalid unicode characters to put into the varchar column in the database. Possibly you could change your schema to be binary but then it makes debugging and reading the database more difficult.

equals - I agree.

hashcode - I agree.

There is a UserType.isMutable() call on the interface so I suspect that a lot of the things you queried might be handled higher up in the hibernate code without calling into this UserType implementation.
My implementation is as much an example as anything else so from it you can work out all the things you need to do (and the way you need to do them) as if it was really a user defined class.

21/01/10 @ 11:47
Comment from: Steve [Visitor]

Have the same problem as Gian Paolo with my column type : Char(1)

Anyone have a solution ?


02/03/11 @ 16:37
Comment from: brndnbg [Visitor]

Hi, thanks for the tutorial! In UuidUserType, method deepCopy, performance can be improved by changing:

UUID.fromString (other.toString ()) ;


newUUID(other.getMostSignificantBits(), other.getLeastSignificantBits());

05/02/12 @ 15:19

Leave a comment

Your email address will not be revealed on this site.

Your URL will be displayed.
(For my next comment on this site)
(Allow users to contact me through a message form -- Your email will not be revealed!)