2 つのクラスで HQL を使用して結果を取得しようとしています。1 つのテーブルでは機能しますが、2 つのテーブルでは機能しません。
以下の 2 つのエンティティ。
public class A_CUSTOMER
{
public virtual string CUSTOMER_NO { get; set; }
public virtual string ADDRESS_LINE { get; set; }
public virtual IList<A_ACCOUNT> ACCOUNTS { get; set; }
}
public class A_ACCOUNT
{
public virtual string AC_NO { get; set; }
public virtual string CUST_NO { get; set; }
public virtual string CCY { get; set; }
public virtual string AVL_BAL { get; set; }
public virtual A_CUSTOMER CUSTOMER { get; set; }
}
以下のクラスのマッピング。
public class A_CUSTOMERMap:ClassMap<A_CUSTOMER>
{
public A_CUSTOMERMap()
{
Id(x => x.CUSTOMER_NO);
Map(x => x.ADDRESS_LINE);
HasMany(x => x.ACCOUNTS).KeyColumns.Add("CUST_NO");
}
}
public class A_CUST_ACCOUNTMap:ClassMap<A_CUST_ACCOUNT>
{
public A_CUST_ACCOUNTMap()
{
Id(x => x.AC_NO);
Map(x=>x.CUST_NO);
Map(x => x.AVL_BAL);
Map(x => x.CCY);
References(x => x.CUSTOMER,"CUST_NO");
}
}
今、コントローラーに次のようなコードがあります。
string myString = "1001,1002,1003,1004,1005";
var indNumbers = myString.Split(',');
string qry = @"select h.AC_NO,h.BRANCH_CODE,h.CUST_NO,h.CCY,h.AVL_BAL ,g.ADDRESS_LINE"+
"from A_ACCOUNT as h,A_CUSTOMER g "+
"where h.CUST_NO=g.CUSTOMER_NO AND h.AC_NO IN (:list)";
;
res = session.CreateQuery(qry)
.SetParameterList("list", indNumbers)
.List();
別のクエリ文字列も試しました:
string qry = @"select h.AC_NO,h.BRANCH_CODE,h.CUST_NO,h.CCY,h.AVL_BAL ,g.ADDRESS_LINE"+
"from A_ACCOUNT as h left join A_CUSTOMER g on "+
"h.CUST_NO=g.CUSTOMER_NO"+
"where h.AC_NO IN (:list)";
以下にエラーが発生しました。どんな助けでも大歓迎です。
NHibernate.Hql.Ast.ANTLR.QuerySyntaxException was unhandled by user code
HResult=-2146232832
Message=Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. near line 1, column 83
Source=NHibernate
StackTrace:
at NHibernate.Hql.Ast.ANTLR.ErrorCounter.ThrowQueryException()
at NHibernate.Hql.Ast.ANTLR.HqlParseEngine.Parse()
at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryString, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory)
at NHibernate.Engine.Query.HQLStringQueryPlan.CreateTranslators(String hql, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory)
at NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory)
at NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory)
at NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(String queryString, Boolean shallow, IDictionary`2 enabledFilters)
at NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(String query, Boolean shallow)
at NHibernate.Impl.AbstractSessionImpl.CreateQuery(String queryString)
at MvcApplication2.Controllers.CustAccountController.GetCustData(jQueryDataTableParamModel param) in ...
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
InnerException: