1

複合キーを持つ連想テーブルがあります。いくつかの値(複合キー)に基づいて選択する名前付きクエリを実行しようとしています。

コードは次のようになります。

@Entity
@NamedQueries({
@NamedQuery(name = "MW.findAll", query = "SELECT mw FROM MemberWorkout mw"),
@NamedQuery(name = "MW.find1", query = "SELECT mw FROM MemberWorkout mw WHERE mw.SocialSecurity LIKE :SocialSecurity"), })
@Table(name = "MemberWorkout")
public class MemberWorkout implements Serializable {

private Member member;
private Workout workout;
private String date;
private MWId mwId;

@EmbeddedId
public MWId getId() {
    return mwId;
}

public void setId(MWId mwId) {
    this.mwId = mwId;
}
....
@ManyToOne
@JoinColumn(name = "SocialSecurity", insertable = false, updatable = false)
public Member getMember() {
    return member;
}

public void setMember(Member member) {
    this.member = member;
}

これは、これをデプロイしてサーバー(JBOSS)を起動したときに発生する最初のエラーです。

ERROR [org.hibernate.internal.SessionFactoryImpl] (MSC service thread 1-1) HHH000177:   Error in named query: MW.find1: org.hibernate.QueryException: could not resolve property: SocialSecurity of: org.ics.ejb.MemberWorkout [SELECT mw FROM org.ics.ejb.MemberWorkout mw WHERE mw.SocialSecurity LIKE :SocialSecurity]
at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:83) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:77) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1809) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.hql.internal.ast.tree.FromElementType.getPropertyType(FromElementType.java:313) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.hql.internal.ast.tree.FromElement.getPropertyType(FromElement.java:485) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.hql.internal.ast.tree.DotNode.getDataType(DotNode.java:598) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.hql.internal.ast.tree.DotNode.prepareLhs(DotNode.java:266) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.hql.internal.ast.tree.DotNode.resolve(DotNode.java:213) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:118) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:114) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.hql.internal.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:883) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1246) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4252) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3874) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1923) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:782) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:583) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:287) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:235) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:101) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:119) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.internal.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:974) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:485) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:84) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_11]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_11]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_11]
4

1 に答える 1

0

問題を正しく理解していれば、は埋め込み可能なSocialSecurityフィールドです。MWIdクエリを使用してアクセスする場合は、次のように埋め込みIDを介してアクセスする必要があります。

SELECT mw FROM MemberWorkout mw WHERE mw.id.SocialSecurity...

あなたのコードのように、プロパティ名は大文字になっていると思います。そうでない場合は、適切な名前に置き換えてください。

プロパティアクセスを使用していることに注意してください。つまり、アクセサメソッドには注釈が付けられているため、JavaBean標準に従ってクエリでプロパティに名前を付ける必要があります(getId()つまり、HQLとJPQLはプロパティにとしてアクセスしますid)。フィールドに注釈を付ける場合は、クエリをに変更する必要がありますmwId

于 2013-03-13T14:11:28.147 に答える