How to map User Data Type (Composite Type) with Hibernate

99封情书 提交于 2019-12-06 06:07:40

Let me know if this solves the issue. Here is an example of postgres/hibernate implementation http://www.hibernatespatial.org/tutorial.html

or the other info piece that might be useful for this situation is:

Am assuming that you have declared your Java objects with the entity annotation. Create a ContactUsetype object extending Hibernate Usertype object.

public Object nullSafeGet(ResultSet resultSet, String[] email, String[] phone, String[] mobile, String[] other, Object owner)
throws HibernateException, SQLException {
assert email.length == 1;
assert phone.length == 1;
assert mobile.length==1;
assert other.length==1

if (resultSet.wasNull()) {
return null;
}
final Contact contactVariable = new Contact(resultSet.getObject(email[0]).toString()
                                       ,resultSet.getObject(phone[0]).toString(),
                                        resultSet.getObject(mobile[0]).toString(),
                                        resultSet.getObject(other[0]).toString());
return contactVariable;
}

public void nullSafeSet(PreparedStatement statement, Object value, int index)
throws HibernateException, SQLException {
statement.setObject(index, value);
}
}

Finally when you create users object

Users user= new User(..., new Contact ("(some@email.com,123-456-4566,111-11-1111,aim)")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!