我正在使用JPQL。我有一个表格,其中的字段是
1. Name DataType-varchar
2. sub DataType-BIT
POJO 文件中的
private String name;
private byte sub;
插入成功为:
姓名=约翰 子= 0
现在我使用以下方式查询此表:
query = em.createQuery("SELECT c FROM Sample c WHERE c.name = '"+ (name)+ "'", Sample.class);
发生异常:
javax.persistence.PersistenceException: Exception [EclipseLink-3002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.ConversionException
Exception Description: The object [false], of class [class java.lang.Boolean], from mapping [org.eclipse.persistence.mappings.DirectToFieldMapping[sub-->sample.SUB]] with descriptor [RelationalDescriptor(com.org.Test --> [DatabaseTable(sample)])], could not be converted to [class java.lang.Byte].
我认为在获取值时,内部将位视为错误。 我该如何解决这个问题?
答案 0 :(得分:2)
我认为你应该在这里使用布尔。
答案 1 :(得分:0)
尝试在模型类中将类型设置为boolean而不是byte。