[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3579?page=c...
]
Steve Ebersole commented on HHH-3579:
-------------------------------------
Well unfortunately I could not get much help on postgresql's irc channel. I did dig
into the JDBC driver code as well as I could. AFAICT, the pertinent snippets appeared to
be:
{code:title=http://cvs.pgfoundry.org/cgi-bin/cvsweb.cgi/jdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java?rev=1.108&content-type=text/x-cvsweb-markup}
protected Object internalGetObject(int columnIndex, Field field) throws SQLException
{
switch (getSQLType(columnIndex))
{
...
default:
String type = getPGType(columnIndex);
...
if (type.equals("uuid"))
return getUUID(getString(columnIndex));
...
}
}
/**
* Newer JVMs will return a java.util.UUID object, but it isn't
* available in older versions.
*/
protected Object getUUID(String data) throws SQLException
{
return data;
}
{code}
and
{code:title=http://cvs.pgfoundry.org/cgi-bin/cvsweb.cgi/jdbc/pgjdbc/org/postgresql/jdbc3g/AbstractJdbc3gResultSet.java?rev=1.1&content-type=text/x-cvsweb-markup}
protected Object getUUID(String data) throws SQLException
{
UUID uuid;
try {
uuid = UUID.fromString(data);
} catch (java.lang.IllegalArgumentException iae) {
throw new PSQLException(GT.tr("Invalid UUID data."),
PSQLState.INVALID_PARAMETER_VALUE, iae);
}
return uuid;
}
{code}
Bottom line, it does appear to map its UUID datatype to Types#OTHER. Ugh! Guess we will
have to live with that. As an example of the potential clash in this approach, they also
appear to do the same with a custom "refcursor" data type; so it is impossible
for an app wanted to define types for both "uuid" and "recursor" and
have schema export work. Also, "auto type discovery" in native sql query
support would be messed up since only one or the other could be mapped.
Support for PostgreSQL UUID data type
-------------------------------------
Key: HHH-3579
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3579
Project: Hibernate Core
Issue Type: New Feature
Components: core
Affects Versions: 3.3.1
Reporter: Olivier Van Acker
Assignee: Steve Ebersole
Fix For: 3.6
Attachments: patch_HH_3579_Hibernate.txt, patch_HH_3579_NullableType.txt,
patch_HH_3579_PostgresSQLDialect.txt, patch_HH_3579_TypeFactory.txt,
patch_HH_3579_UuidType.txt
PostgreSQL has since version 8.3 UUID as data type nativly supported in the database.
The only way to get this to work in Hibernate is to add <column name="id"
sql-type="uuid"/> to your mappings file (or @columnDefinition via
annotations)
and create your own custom usertype (e.g. public class UUIDUserType implements UserType,
Serializable {..} ) and map this to java.util.UUID
worth mentioning is that java.util.UUID is only introduced in java 1.5 so there might be
a backwards compatibility problem
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira