2017-09-12 18 views
0

を解決できませんでした:org.hibernate.QueryException--は、私は以下のようなエンティティを持っている財産

@Entity 
public class Country implements Serializable { 
    private static final long serialVersionUID = 1L; 
    @Id 
    private Long id; 
    @Type(type="secureString") //This is my custom user type and it is working fine in the sense I am able to insert, select and update records using it. 
    private SecureString   nationality; 
    // getters and setters 
} 

SecureStringクラスは以下の通りです:

public class SecureString implements Serializable { 


    private static final long serialVersionUID = 1L; 
    private String actualValue; 

    private String formattedValue; 
    //getters and setters 
} 

The column name in db for this attibute is named "nationality"

だけあります1つの列は国籍に対応します。私はこのためにHibernate Custom UserTypeを使用しています。以前は、このプロパティはSecureStringではなくStringでした。

私は例外を取得しています形成java.lang.IllegalArgumentException: org.hibernate.QueryException: could not resolve property: actualValue of: mypackge.Country.

HQLは次のとおりです。

select s FROM mypackage.Country s 
WHERE LOWER(s.nationality.actualValue) LIKE LOWER(:nationality_actualValue); 

ログを1として、私たちはHibernateは変換中Countryクラス内の名前actualValueを持つプロパティを検索しようとしていることがわかりますHQ1~SQ1。この問題をどうやって解決するのですか?

注:同じEntityクラスでSecureString型の複数の属性を使用できます。

ログ:

at org.hibernate.QueryException.generateQueryException(QueryException.java:120) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:217) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:141) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:115) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:77) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:153) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:545) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:654) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    ... 142 common frames omitted 
Caused by: org.hibernate.QueryException: could not resolve property: actualValue of: mypackage.Country 
    at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:62) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:56) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1859) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.ast.tree.FromElementType.getPropertyType(FromElementType.java:393) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.ast.tree.FromElement.getPropertyType(FromElement.java:512) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.ast.tree.DotNode.getDataType(DotNode.java:660) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.ast.tree.DotNode.prepareLhs(DotNode.java:264) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.ast.tree.DotNode.resolveInFunctionCall(DotNode.java:178) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:1030) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1286) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4699) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.functionCall(HqlSqlBaseWalker.java:2729) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1361) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4699) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:4313) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2134) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2087) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2084) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2084) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2084) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2084) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2062) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:813) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:607) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:311) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:259) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:261) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:189) ~[hibernate-core-5.2.8.Final.jar:5.2.8.Final] 
    ... 148 common frames omitted 
+0

あなたはログを投稿してもらえますか? – Aldeguer

+0

あなたの 'SecureString'はマップされていません! –

+0

@兵器宮本ポイントを取得していません。カスタムUserTypeを作成し、このフィールドに注釈を付けました。他にどのようなマッピングがありますか? SecureStringはエンティティではありません。 – Aman

答えて

0

、このような何かコンバーターを作成してみてください:

@Converter 
public class SecureConverter implements AttributeConverter<SecureString, String> 
{ 
    @Override 
    public String convertToDatabaseColumn(SecureString ss) { 
     return ss.getActualValue(); 
    } 
    @Override 
    public SecureString convertToEntityAttribute(String s) 
    { 
     SecureString result = new SecureString(); 
     result.setActualValue(s); 
     return result; 
    } 
} 

をそして、あなたの属性にそれを使用する:

@Entity 
public class Country implements Serializable 
{ 
    private static final long serialVersionUID = 1L; 

    @Id 
    private Long id; 
    @Converter(converter = Secureconverter.class) 
    private SecureString nationality; 

    // getters and setters 
} 
+0

ConverterとCustom UserTypeを一緒に使うことはできますか?また、私はpackage-info.javaのUserTypesを宣言するのと同じように、このコンバータをどこかに登録する必要がありますか? – Aman

関連する問題