這樣的:
@Column(name = "dir", nullable = false, columnDefinition = "ltree")
@Type(type = "ru.zen0n.hibernate.types.LTreeType")
private String path;
這:
package ru.zen0n.hibernate.types;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;
public class LTreeType implements UserType {
@Override
public int[] sqlTypes() {
return new int[] {Types.OTHER};
}
@SuppressWarnings("rawtypes")
@Override
public Class returnedClass() {
return String.class;
}
@Override
public boolean equals(Object x, Object y) throws HibernateException {
return x.equals(y);
}
@Override
public int hashCode(Object x) throws HibernateException {
return x.hashCode();
}
@Override
public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
throws HibernateException, SQLException {
return rs.getString(names[0]);
}
@Override
public void nullSafeSet(PreparedStatement st, Object value, int index)
throws HibernateException, SQLException {
st.setObject(index, value, Types.OTHER);
}
@Override
public Object deepCopy(Object value) throws HibernateException {
return new String((String)value);
}
@Override
public boolean isMutable() {
return false;
}
@Override
public Serializable disassemble(Object value) throws HibernateException {
return (Serializable)value;
}
@Override
public Object assemble(Serializable cached, Object owner)
throws HibernateException {
return cached;
}
@Override
public Object replace(Object original, Object target, Object owner)
throws HibernateException {
// TODO Auto-generated method stub
return deepCopy(original);
}
}
謝謝,看起來很有希望。可悲的是,我們決定放棄ORM,因爲時間不夠,所以我可以稍後再嘗試。我給了它一個。 – NagyI 2011-05-18 08:39:59
我們在我們的解決方案中使用了Spring的SQL行映射器。它實際上並不是一個ORM層,但我們只有幾張表,所以它仍然非常可維護。 因爲我沒有時間去測試它,而你的是這裏唯一相關的答案,我接受它。 – NagyI 2011-06-14 10:14:03