Using guid.comb for character(36)

9 views
Skip to first unread message

Kenneth Siewers Møller

unread,
Jul 1, 2009, 8:04:24 AM7/1/09
to nhu...@googlegroups.com
Hi

This might be a simple question to answer, but here goes.

We're running a PostgreSQL 8.1 DBMS, which doesn't support UUID. My idea is therefore to continue using GUID's as PK's in my domain model, but simply persist them as character(36) in the database. Is this possible? I've tried just changing the column to character(36), but this causes NH to produce the error "operator does not exist: character = uuid", which is resonable... Changing the mapping to type "string" creates a conversion exception - again quite understandable...

I'd rather avoid creating a custom usertype as the DBMS probably will be upgraded at some point, making this a somewhat irellevant implementation...

Any ideas?

Ken Egozi

unread,
Jul 1, 2009, 8:26:59 AM7/1/09
to nhu...@googlegroups.com
a guid is a 128bit number
character(36) is 288.  even if you skip the '-' chars you're still at 256.  and if characters() is unicode ...
using a too large field for indexing, especially for PK, might not be such a good idea.
is there any kind of a binary[128] field you can use instead?  then we'll discuss the mapping

2009/7/1 Kenneth Siewers Møller <ken...@siewers.dk>

Kenneth Siewers Møller

unread,
Jul 1, 2009, 9:50:13 AM7/1/09
to nhu...@googlegroups.com
Hmm, unfortunately there isn't any binary column. I guess theres a byte array ("bytea"), but i don't know if that's any good.
I can see your point in using character(36) is a bad idea, but I was simply just copying the guid generated from .NET (which includes the dashes), thinking that a plain character string in the same length would be enough. My current implementation isn't that advanced, so indexing isn't a real issue at the moment.

My point is also that I need to be able to convert the column to a "real" uuid when we make a switch to the new version at some point (8.3)...

2009/7/1 Ken Egozi <ego...@gmail.com>

Kenneth Siewers Møller

unread,
Jul 1, 2009, 12:30:17 PM7/1/09
to nhu...@googlegroups.com
Okay, the db type "bytea" is in fact binary data... So, with this in place, how can I persist a Guid in that?

2009/7/1 Kenneth Siewers Møller <kenneth...@gmail.com>

Fabio Maulo

unread,
Jul 1, 2009, 12:51:06 PM7/1/09
to nhu...@googlegroups.com
2009/7/1 Kenneth Siewers Møller <kenneth...@gmail.com>
Okay, the db type "bytea" is in fact binary data... So, with this in place, how can I persist a Guid in that?

Take care. The matter is not only the representation but how the DataProvider will interpret a Guid parameter.

--
Fabio Maulo

Kenneth Siewers Møller

unread,
Jul 1, 2009, 12:54:17 PM7/1/09
to nhu...@googlegroups.com
Well, I ended up creating a simple enhanced usertype converting from string to guid and vice verca... It's actually a very crude implementation, but does what is intended.

Am I correct to assume that IEnhancedUserType is the right approach for a custom identifier type?


2009/7/1 Fabio Maulo <fabio...@gmail.com>
Reply all
Reply to author
Forward
0 new messages