postgres的最新Java JDBC驱动程序声称本机支持UUID; 与Postgres 9.2(mac)对抗.
实际上,当使用PreparedStatement时,我可以单步执行驱动程序代码,甚至可以遍历AbstractJdbc3gStatement.java中专门的"setUuid"函数.根据所有迹象,它应该"正常工作".
但是,它不起作用.数据库收回错误,我收到错误:
Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: uuid = bytea
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Position: 139
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157) ~[postgresql-9.2-1002.jdbc4.jar:na]
Run Code Online (Sandbox Code Playgroud)
是的,确实,JDBC驱动程序中的setUuid会将其作为bytea发送:
private void setUuid(int parameterIndex, UUID uuid) throws SQLException {
if (connection.binaryTransferSend(Oid.UUID)) {
byte[] val = new byte[16];
ByteConverter.int8(val, 0, uuid.getMostSignificantBits());
ByteConverter.int8(val, 8, uuid.getLeastSignificantBits());
bindBytes(parameterIndex, val, Oid.UUID);
} else {
bindLiteral(parameterIndex, uuid.toString(), Oid.UUID);
}
}
Run Code Online (Sandbox Code Playgroud)
是什么赋予了?实际数据库中是否需要一些魔法符文来祝福这种转换?
我似乎无法正确注册我的Jackson ObjectMapper模块.
我正在使用Guice + Jersey + Jackson(FasterXML)堆栈.
我已经按照如何基于各种问题自定义了ObjectMapper.特别是,我声明了一个ContextResolver,标记为@ javax.ws.rs.ext.Provider和@javax.inject.Singleton.
我有一个GuiceServletContextListener:
@Override
protected Injector getInjector() {
Injector injector = Guice.createInjector(new DBModule(dataSource),
new ServletModule()
{
@Override
protected void configureServlets() {
// Mapper
bind(JacksonOMP.class).asEagerSingleton();
// ...
Map<String, String> initParams = new HashMap<String, String>();
initParams.put("com.sun.jersey.config.feature.Trace",
"true");
initParams.put("com.sun.jersey.api.json.POJOMappingFeature", "true");
serve("/services/*").with(
GuiceContainer.class,
initParams);
}
});
return injector;
}
Run Code Online (Sandbox Code Playgroud)
映射器已定义
import javax.inject.Singleton;
import javax.ws.rs.Produces;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
@Provider
@Singleton
@Produces
public class JacksonOMP implements ContextResolver<ObjectMapper> {
@Override
public ObjectMapper getContext(Class<?> aClass) {
final ObjectMapper mapper = …Run Code Online (Sandbox Code Playgroud)