JPQL SELECT Distinct Query with clob Column 在 WAS7 上工作正常,但 WAS9 不工作
JPQL SELECT Distinct Query with clob Column works fine on WAS7, but WAS9 doesn't
我正在使用 Spring 基于 3.0 的 JPA2.0
@Entity
@Table(name = "MY_TABLE", schema = "DB2XXXX")
public class MyTable implements java.io.Serializable,Comparable<MyTable> {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "MY_TABLE_ID")
private BigInteger myTableId;
@Column(name = "FREETEXT")
private String freetext;
public MyTable() {
}
public MyTable(BigInteger myTableId,String freetext) {
super();
this.myTableId = myTableId;
this.freetext = freetext
}
public BigInteger getMyTableId() {
return myTableId;
}
public void setMyTableId(myTableId) {
this.myTableId = myTableId;
}
public String getFreetext() {
return freetext;
}
public void setFreetext(String freetext) {
this.freetext = freetext;
}
}
freetext 是 clob 列
public List<MyTable> getData(BigInteger myTableId) throws Exception {
StringBuilder jpql = new StringBuilder();
List<MyTable> resultList = null;
try {
jpql.append("SELECT distinct data FROM MyTable data ")
resultList = findWithJpql(entityManager, jpql.toString(), null,false, 0, 0);
} catch (Exception e) {
}
return resultList;
}
@TransactionAttribute(value = TransactionAttributeType.REQUIRED)
@SuppressWarnings("unchecked")
public <T> T findWithJpql(EntityManager em, String jpql, Map<String, Object> conditions, boolean singleResult, int firstResult, int maxResult) {
Query query = em.createQuery(jpql);
if(firstResult > 0){
query.setFirstResult(firstResult);
}
if(maxResult > 0){
query.setMaxResults(maxResult);
}
if(conditions != null && conditions.size() > 0){
for(String condition : conditions.keySet()){
query.setParameter(condition, conditions.get(condition));
}
}
if(singleResult){
try{
return (T)query.getSingleResult();
}catch(NoResultException nrex){
return null;
}
}else{
T a = (T)query.getResultList();
return a;
}
}
在WAS9中调用查询方法时Db2错误代码-134:
在同时指定 DISTINCT 的 SELECT 列表中不允许长度属性大于 255 字节的字符串值。
**但是这个查询在 WAS7 上工作正常 **
[21/12/2564,10:28:10:731 ICT] 0000018e eclipselink W 异常 [EclipseLink-4002](Eclipse 持久性服务 - 2.6.8.WAS-v20181218-0accd7f):org.eclipse.persistence.exceptions.DatabaseException
内部异常:com.ibm.db2.jcc.am.SqlSyntaxErrorException:DB2 SQL 错误:SQLCODE=-134,SQLSTATE=42907,SQLERRMC=REMARK , 驱动程序=4.25.13
错误代码:-134
内部异常:com.ibm.db2.jcc.am.SqlSyntaxErrorException:DB2 SQL 错误:SQLCODE=-134,SQLSTATE=42907,SQLERRMC=备注,驱动程序=4.25.13
错误代码:-134
如果 freetext
是 Clob 列,请尝试使用 @Lob
对其进行正确注释。检查此 post Using EclipseLink JPA to bind Strings larger than 255 characters .
该错误可能与 WAS7 和 9 之间的 JPA 提供程序更改有关(以前是 OpenJPA)。如果您不关心 JPA 2.1,您可以切换回 2.0 OpenJPA,例如使用 wsadmin
:
wsadmin>AdminTask.modifyJPASpecLevel('[-node myNode -server server1 -specLevel 2.0]')
CWWJP8813I: The JPA specification compliance level for Server server1 has been successfully set to JPA 2.0.
我正在使用 Spring 基于 3.0 的 JPA2.0
@Entity
@Table(name = "MY_TABLE", schema = "DB2XXXX")
public class MyTable implements java.io.Serializable,Comparable<MyTable> {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "MY_TABLE_ID")
private BigInteger myTableId;
@Column(name = "FREETEXT")
private String freetext;
public MyTable() {
}
public MyTable(BigInteger myTableId,String freetext) {
super();
this.myTableId = myTableId;
this.freetext = freetext
}
public BigInteger getMyTableId() {
return myTableId;
}
public void setMyTableId(myTableId) {
this.myTableId = myTableId;
}
public String getFreetext() {
return freetext;
}
public void setFreetext(String freetext) {
this.freetext = freetext;
}
}
freetext 是 clob 列
public List<MyTable> getData(BigInteger myTableId) throws Exception {
StringBuilder jpql = new StringBuilder();
List<MyTable> resultList = null;
try {
jpql.append("SELECT distinct data FROM MyTable data ")
resultList = findWithJpql(entityManager, jpql.toString(), null,false, 0, 0);
} catch (Exception e) {
}
return resultList;
}
@TransactionAttribute(value = TransactionAttributeType.REQUIRED)
@SuppressWarnings("unchecked")
public <T> T findWithJpql(EntityManager em, String jpql, Map<String, Object> conditions, boolean singleResult, int firstResult, int maxResult) {
Query query = em.createQuery(jpql);
if(firstResult > 0){
query.setFirstResult(firstResult);
}
if(maxResult > 0){
query.setMaxResults(maxResult);
}
if(conditions != null && conditions.size() > 0){
for(String condition : conditions.keySet()){
query.setParameter(condition, conditions.get(condition));
}
}
if(singleResult){
try{
return (T)query.getSingleResult();
}catch(NoResultException nrex){
return null;
}
}else{
T a = (T)query.getResultList();
return a;
}
}
在WAS9中调用查询方法时Db2错误代码-134: 在同时指定 DISTINCT 的 SELECT 列表中不允许长度属性大于 255 字节的字符串值。 **但是这个查询在 WAS7 上工作正常 **
[21/12/2564,10:28:10:731 ICT] 0000018e eclipselink W 异常 [EclipseLink-4002](Eclipse 持久性服务 - 2.6.8.WAS-v20181218-0accd7f):org.eclipse.persistence.exceptions.DatabaseException 内部异常:com.ibm.db2.jcc.am.SqlSyntaxErrorException:DB2 SQL 错误:SQLCODE=-134,SQLSTATE=42907,SQLERRMC=REMARK , 驱动程序=4.25.13 错误代码:-134
内部异常:com.ibm.db2.jcc.am.SqlSyntaxErrorException:DB2 SQL 错误:SQLCODE=-134,SQLSTATE=42907,SQLERRMC=备注,驱动程序=4.25.13 错误代码:-134
如果 freetext
是 Clob 列,请尝试使用 @Lob
对其进行正确注释。检查此 post Using EclipseLink JPA to bind Strings larger than 255 characters .
该错误可能与 WAS7 和 9 之间的 JPA 提供程序更改有关(以前是 OpenJPA)。如果您不关心 JPA 2.1,您可以切换回 2.0 OpenJPA,例如使用 wsadmin
:
wsadmin>AdminTask.modifyJPASpecLevel('[-node myNode -server server1 -specLevel 2.0]')
CWWJP8813I: The JPA specification compliance level for Server server1 has been successfully set to JPA 2.0.