gpt4 book ai didi

java - 异常 [EclipseLink-3002](Eclipse 持久性服务 - 2.6.2.qualifier): org. eclipse.persistence.exceptions.ConversionException

转载 作者:太空宇宙 更新时间:2023-11-04 10:42:04 25 4
gpt4 key购买 nike

我正在尝试在 Java 实体类中获取表记录,其中一列被定义为 CLOB。当我执行选择查询时,出现以下错误:-

[EclipseLink-3002](Eclipse 持久性服务 - 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)

请帮忙,我不确定上面的代码有什么问题,有人可以帮助我吗?提前致谢!!

最佳答案

CLOB 需要是 char[] 而不是 byte[] ..... byte[] 用于 BLOB

关于java - 异常 [EclipseLink-3002](Eclipse 持久性服务 - 2.6.2.qualifier): org. eclipse.persistence.exceptions.ConversionException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48862391/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com