私はこの問題をあまりにも長い間見つめてきました。.list() ライン スプリングを実行すると、.add(Restrictions.in("LocationCode", locations)) に関して例外がスローされます。 java.util.Arrays$ArrayList は java.lang.String にキャストできません。
Restrictions.in は (string, Object[]) no を期待していますか??
Restrictions.inに渡すときに何が欠けているか誰かが指摘できますか??
public List getIDsByDivision(String SelectedAccountCode,
List SelectedDivision, String SelectedLocation) {
List IDs=null;
String result="--Select--";
Session session=null;
String[] locations=SelectedLocation.split(",");
try
{
session=sessionFactory.openSession();
if(null!=SelectedAccountCode && !SelectedAccountCode.equals("--Select--")
&&SelectedDivision.size()>0&&!SelectedDivision.equals("--Select--")
&&locations.length>0&&!SelectedLocation.equals("--Select--"))
{
IDs=session.createCriteria(Customer.class)
// TODO fix this to location
.setProjection(Projections.distinct(Projections.property("ID")))
.add(Restrictions.eq("AcctCode", SelectedAccountCode))
.add(Restrictions.eq("Division", SelectedDivision))
.add(Restrictions.in("LocationCode", locations ))
.list();
}
顧客クラス
package <removed>;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Customer {
@Id
private String ID;
@Column
private String Name;
private String AcctCode;
private String LocationCode;
private String Division;
private String ContactEmail;
public Customer(){}
public Customer(String iD, String name, String acctCode,
String locationCode, String division, String contactEmail) {
super();
ID = iD;
Name = name;
AcctCode = acctCode;
LocationCode = locationCode;
Division = division;
ContactEmail=contactEmail;
}
public String getID() {
return ID;
}
public void setID(String iD) {
ID = iD;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getAcctCode() {
return AcctCode;
}
public void setAcctCode(String acctCode) {
AcctCode = acctCode;
}
public String getLocationCode() {
return LocationCode;
}
public void setLocationCode(String locationCode) {
LocationCode = locationCode;
}
public String getDivision() {
return Division;
}
public void setDivision(String division) {
Division = division;
}
public String getContactEmail() {
return ContactEmail;
}
public void setContactEmail(String contactEmail) {
ContactEmail = contactEmail;
}
}