在我的Java应用程序中,我想在Postgres表中插入一条新记录,其中一列是JSON类型。
我使用Hibernate 4.x
实体类如下所示:
@NamedNativeQueries({
@NamedNativeQuery(
name = "user.login",
query = "select * from user_login(:ext_user_id, :platform_id, :server_id, :ip_address, :first_name, :last_name, :additional_data)",
resultClass = User.class
)
})
public class User implements Serializable {
...
}
实际代码:
Session session = sessionManager.openDBSession();
Query query = session.getNamedQuery("user.login");
PGobject data = new PGobject();
data.setType("json");
data.setValue(additional_data.toString());
query.setString("ext_user_id", ext_uid)
.setShort("platform_id", (short)platform_id.value())
.setShort("server_id", server_id)
.setString("ip_address", ip_address)
.setString("first_name", fname)
.setString("last_name", lname)
.setParameter("additional_data", data);
UUID sessionId = (UUID) query.uniqueResult();
...
}
失败并显示错误:
org.postgresql.util.PSQLException: ERROR: function user_login(character varying, smallint, smallint,
character varying, character varying, character varying, bytea) does not exist
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Position: 55
我做错了什么?