日期:2014-05-20  浏览次数:20750 次

晚上写的EJB中的怪问题
最近新学的EJB,晚上把原来的东西重写了下,遇到了下面的问题
Entity bean
package project.entity.beans;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="tc_code_unit")
public class CodeUnit implements Serializable {


private String u_code;
private String u_name;
private String flag;

@Id
@Column(name="U_CODE")
public String getU_code() {
return u_code;
}

public void setU_code(String u_code) {
this.u_code = u_code;
}

@Column(name="U_NAME")
public String getU_name() {
return u_name;
}

public void setU_name(String u_name) {
this.u_name = u_name;
}

@Column(name="FLAG")
public String getFlag() {
return flag;
}

public void setFlag(String flag) {
this.flag = flag;
}
}

Session bean
package project.session.beans;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.EntityNotFoundException;
import javax.persistence.NonUniqueResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import project.entity.beans.CodeUnit;

@Stateless
public class PublishCodeUnit implements PublishCodeUnitRemote {
@PersistenceContext(unitName="codeunit") private EntityManager manager;
public CodeUnit getUCode(String u_name) {
Query query = manager.createQuery("from CodeUnit where U_NAME='" + u_name + "'");
CodeUnit codeUnit = (CodeUnit) query.getSingleResult();
return codeUnit;
}

public List findProvinces() {
Query query = manager.createQuery("from CodeUnit where U_CODE in (020000,030000)");
List lists = query.getResultList();
return lists;
}

public List findCities(String province) {
Query query;
if(province.equalsIgnoreCase("xxxxxx")) {
query = manager.createQuery("from CodeUnit where U_CODE in (020100,020200,020300,020400,020500,020600,020700,020800,020900)");
} else {
query = manager.createQuery("from CodeUnit where U_CODE in (030100,030200,030300,030400,030500,030600)");
}
List lists = query.getResultList();
return lists;
}
}
其他的一些配置都是对的,执行报错信息org.hibernate.hql.ast.QuerySyntaxException: unexpected token:.。。800,900。。。
然后mysql查询020800,020900都有值。期间也google很多,还是没有什么头绪。最后我把DB中的020800和020900换为021000很021100就好了。。。。。。。
没有头绪,赐教赐教,谢谢。

------解决方案--------------------
请问你 U_CODE 是什么类型! 你EQL里又是用的什么类型?