我正在开发一个应用程序:
我想将PostgreSQL文本数据类型用于某些String属性.据我所知,在JPA中,这应该是正确的注释,在PostgreSQL中使用文本:
@Entity
public class Product{
...
@Lob
private String description;
....
}
Run Code Online (Sandbox Code Playgroud)
当我像这样注释我的实体时,我会遇到如下错误:http: //www.shredzone.de/cilla/page/299/string-lobs-on-postgresql-with-hibernate-36.html
简而言之:看起来hibernate和jdbc并不是clob/text-types的完美结合.
描述的解决方案正在运行:
@Entity
public class Product{
...
@Lob
@Type(type = "org.hibernate.type.TextType")
private String description;
...
}
Run Code Online (Sandbox Code Playgroud)
但这有一个明显的缺点:源代码在编译时需要休眠,这应该是不必要的(这是首先使用JPA的一个原因).
另一种方法是使用这样的列注释:
@Entity
public class Product{
...
@Column(columnDefinition = "text")
private String description;
...
}
Run Code Online (Sandbox Code Playgroud)
哪个工作得很好,但是:现在我遇到了具有文本类型的数据库(也称为文本;))如果将来会使用另一个数据库,注释很容易被忽略.因此,可能很难找到可能的错误,因为数据类型是在String中定义的,因此在运行时之前无法找到.
有没有解决方案,这很容易,我只是看不到它?我非常确定我不是唯一一个将JPA与Hibernate和PostgreSQL结合使用的人.所以我有点困惑,我找不到更多像这样的问题.
只是为了完成这个问题,persistence.xml看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="entityManager">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.app.model.Product</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<property …Run Code Online (Sandbox Code Playgroud) 基于这个Jaspic示例,我为以下validateRequest方法编写了以下方法ServerAuthModule:
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject,
Subject serviceSubject) throws AuthException {
boolean authenticated = false;
final HttpServletRequest request =
(HttpServletRequest) messageInfo.getRequestMessage();
final String token = request.getParameter("token");
TokenPrincipal principal = (TokenPrincipal) request.getUserPrincipal();
Callback[] callbacks = new Callback[] {
new CallerPrincipalCallback(clientSubject, (TokenPrincipal) null) };
if (principal != null) {
callbacks = new Callback[] {
new CallerPrincipalCallback(clientSubject, principal) };
authenticated = true;
} else {
if (token != null && token.length() == Constants.tokenLength) {
try { …Run Code Online (Sandbox Code Playgroud)