我正在尝试在Java Entity类中获取Table记录,其中一列定义为CLOB。当我执行我的选择查询时,我得到以下错误: -
[EclipseLink-3002](Eclipse Persistence Services - 2.6.2.qualifier):org.eclipse.persistence.exceptions.ConversionException错误。
以下是代码的细节..........
在数据库中,我有CLOB列。我正在实体上执行选择查询。以下是详细信息。
在数据库表中,MSG列定义为CLOB。
我的实体课程如下。
@Entity
@Table( name = "MyTable", schema="TEST" )
@NamedQueries({
@NamedQuery( name = "MyTable.findByChangeKey", query = "SELECT t FROM MyTable t WHERE t.changeKey = :changeKey)
} )
public class MyTable implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic( optional = false )
@Column( name = "ID", nullable = false )
private Integer msgId;
@Basic( optional = false )
@Column( name = "CHANGE_KEY", nullable = false, length = 15 )
private String changeKey;
@Column( name = "MSG")
@Lob
private byte[] msg;
public Tsmtidsm() {
}
public byte[] getMsg() {
if(msg!=null)
{
return (byte[])msg.clone();
}
else
{
return msg;
}
}
public void setMsg( byte[] msg ) {
if(msg!=null)
{
this.msg = (byte[])msg.clone();
}
else
{
this.msg=null;
}
}
public Tsmtidsm( Integer msgId ) {
this.msgId = msgId;
}
public Integer getMsgId() {
return msgId;
}
public void setMsgId( Integer msgId ) {
this.msgId = msgId;
}
public String getChangeKey() {
return changeKey;
}
public void setChangeKey( String changeKey ) {
this.changeKey = changeKey;
}
}
及以下是我调用我的选择查询的代码行
Query searchQuery = em.createNamedQuery( "MyTable.findByChangeKey" );
searchQuery.setParameter("changeKey", serialNumber );
List<MyTable> myTable=(List<MyTable>)searchQuery.getResultList();
执行上面的代码时出现以下错误。
Caused by: Exception [EclipseLink-3002] (Eclipse Persistence Services - 2.6.2.qualifier): org.eclipse.persistence.exceptions.ConversionException
Exception Description: The object [[B@2b2d02e5], of class [class java.lang.String], from mapping [org.eclipse.persistence.mappings.DirectToFieldMapping[msg-->TEST.MyTable.MSG]] with descriptor [RelationalDescriptor(com.dao.data.MyTable--> [DatabaseTable(TEST.MyTable)])], could not be converted to [class [B].
at org.eclipse.persistence.exceptions.ConversionException.couldNotConvertToByteArray(ConversionException.java:115)
请帮助,我不确定上面的代码有什么问题,有人可以帮我吗?在此先感谢!!
答案 0 :(得分:0)
CLOB需要char[]
而不是byte[]
..... byte[]
适用于BLOB