Java 为什么在使用JPA执行基本的mySQL搜索时会出现这个错误?
我正在查询我的sql数据库。我有两张桌子: 表1:BusinessAccountJava 为什么在使用JPA执行基本的mySQL搜索时会出现这个错误?,java,mysql,jpa,Java,Mysql,Jpa,我正在查询我的sql数据库。我有两张桌子: 表1:BusinessAccount businessName (String); businessAddress (String); county (int); (county is the Foreign Key for countyId on table 2) 表2:县 countyId (int); countyName (String); 我试图返回county=1的所有业务帐户的列表。我在说以下内容时出错: 您已尝试为设置classja
businessName (String);
businessAddress (String);
county (int); (county is the Foreign Key for countyId on table 2)
表2:县
countyId (int);
countyName (String);
我试图返回county=1的所有业务帐户的列表。我在说以下内容时出错:
您已尝试为设置classjava.lang.Integer
类型的值
参数CountyId
,具有预期的类类型
com.needABuilder.entities.country
来自查询字符串从BusinessAccount u中选择u,其中u.county=:CountyId
当我在BusinessAccount表中搜索整数值county=1的条目时,我不明白为什么会出现此错误。这是我的密码。谢谢你的帮助
public List<BusinessAccount> searchContractors() {
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = factory.createEntityManager();
List<BusinessAccount> contractorList = new ArrayList<BusinessAccount>();
em.getTransaction().begin();
int countyId=1;
Query myQuery = em.createQuery(
"SELECT u FROM BusinessAccount u WHERE u.county=:CountyId");
myQuery.setParameter("CountyId", countyId);
contractorList=myQuery.getResultList();
em.getTransaction().commit();
em.close();
return contractorList;
}
公共列表搜索承包商(){
factory=Persistence.createEntityManagerFactory(Persistence\u UNIT\u NAME);
EntityManager em=factory.createEntityManager();
List contractorList=new ArrayList();
em.getTransaction().begin();
int countyId=1;
Query myQuery=em.createQuery(
“从BusinessAccount u中选择u,其中u.county=:CountyId”);
setParameter(“CountyId”,CountyId);
contractorList=myQuery.getResultList();
em.getTransaction().commit();
em.close();
返回合同列表;
}
这条消息解释了一切<代码>业务帐户。county的类型为county
。它不是Integer
类型。不能将县
与整数
进行比较
您可以将一个县与另一个县进行比较,或者将一个整数与另一个整数进行比较。因此,您想要的(假设country.id
类型为Integer
或int
)是
谢谢,这一点现在看来很明显——我是新手,但我知道现在发生了什么!
select u from BusinessAccount u where u.county.id = :countyId