Oracle and UUID in RAW(16) column

1,445 views
Skip to first unread message

Geir Sveen

unread,
Sep 8, 2015, 3:01:28 PM9/8/15
to Querydsl
Hello, :-)

My company have just started out trying QueryDSL and have stumbled upon a problem related to UUID use in Oracle. In many of our solutions we are using Oracle and UUIDs and saving the UUIDs in columns with data type RAW(16).

The UUID will look like this saved in RAW(16): 8B24EA7A2E404951B628BBC9CE915E08
Basically the hyphens are stripped and the letters are capitalized.

I've tried to use the UtilUUIDType map class here, but it doesn't handle this way of treating UUIDs in Oracle.

I've also tried to create my own class for handling UUIDs extending AbstractType<UUID> and trying to register it:
<customTypes>
     
<customType>com.mycompany.myapp.customtypes.UtilUUIDTypeOracle</customType>
</customTypes>

I get a maven error when trying to compile this saying it failed to execute goal export. I also notice that the UUID field is statically mapped in com.querydsl.sql.JavaTypeMapping to the original UtilUUIDType class, so I'm wondering whether it is possible at all to add a custom implementation here.

Have I misunderstood something here? Is there a way for me to add a custom type on the UUID handling here other than the existing UtilUUIDType?

I'm using Java 8, Maven 2, QueryDSL 4.0.4, Spring boot 1.2.5.

Thanks


timowest

unread,
Sep 9, 2015, 2:54:41 PM9/9/15
to Querydsl
Do you get any error message in the maven goal execution failure?

Geir Sveen

unread,
Oct 5, 2015, 7:03:34 AM10/5/15
to Querydsl
I've cleaned up the maven issue, but the problem now is that com.querydsl.sql.types.UtilUUIDType is still used instead of my custom com.mycompany.myapp.customtypes.UtilUUIDTypeOracle class.

Setting <customType>...</customType> in the pom file doesn't seem to override the existing type.

My class looks like this:

public class UtilUUIDTypeOracle extends AbstractType<UUID> {

public UtilUUIDTypeOracle() {
super(Types.OTHER);
}

public UtilUUIDTypeOracle(int type) {
super(type);
}

@Override
public UUID getValue(ResultSet rs, int startIndex) throws SQLException {
byte[] uuidBytes = rs.getBytes(startIndex);
return uuidBytes != null ? UuidUtils.stringToUUID(uuidBytes.toString()) : null;
}

@Override
public Class<UUID> getReturnedClass() {
return UUID.class;
}

@Override
public void setValue(PreparedStatement st, int startIndex, UUID value) throws SQLException {
st.setBytes(startIndex, value != null ? UuidUtils.toDbString(value).getBytes() : null);
}
}



timowest

unread,
Oct 5, 2015, 2:54:03 PM10/5/15
to Querydsl
The maven configuration won't affect the runtime mapper usage, only the java type in the generated classes.

In your case you will need to register the type in the runtime configuration: http://www.querydsl.com/static/querydsl/4.0.4/apidocs/com/querydsl/sql/Configuration.html
Reply all
Reply to author
Forward
0 new messages