我有一个使用hibernate 3.1和JPA注释的应用程序.它有一些具有byte []属性的对象(1k - 200k大小).它使用JPA @Lob注释,而hibernate 3.1可以在所有主要数据库上读取这些内容 - 它似乎隐藏了JDBC Blob供应商的特性(应该这样做).
@Entity
public class ConfigAttribute {
@Lob
public byte[] getValueBuffer() {
return m_valueBuffer;
}
}
Run Code Online (Sandbox Code Playgroud)
我们不得不升级到3.5,当我们发现hibernate 3.5 在postgresql中打破(并且不会修复)这个注释组合时(没有解决方法).到目前为止我还没有找到明确的解决方法,但我注意到如果我只是删除了@Lob,它使用了postgresql类型的bytea(有效,但只适用于postgres).
annotation postgres oracle works on
-------------------------------------------------------------
byte[] + @Lob oid blob oracle
byte[] bytea raw(255) postgresql
byte[] + @Type(PBA) oid blob oracle
byte[] + @Type(BT) bytea blob postgresql
once you use @Type, @Lob seems to not be relevant
note: oracle seems to have deprecated the "raw" type since 8i.
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种方法来拥有一个可以在主要数据库之间移植的带注释的类(具有blob属性).
我有一个功能
public static Object receviceSigAndData (Socket s) {
byte[] data = null;
try {
DataInputStream din2 = new DataInputStream(s.getInputStream());
int sig_len = 0;
sig_len = din2.readInt();
byte[] sig = new byte[sig_len];
din2.readFully(sig);
int data_len = 0;
data_len = din2.readInt();
data = new byte[data_len];
dsa.update(data);
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return (Object)data;
}
Run Code Online (Sandbox Code Playgroud)
函数返回一个对象,如果对象是字节数组,我该如何将对象转换为byte[]?
byte[] b = (?)receviceSigAndData (socket);
Run Code Online (Sandbox Code Playgroud)
谢谢