【问题标题】:Exception [EclipseLink-3002] (Eclipse Persistence Services - 2.6.2.qualifier): org.eclipse.persistence.exceptions.ConversionException异常 [EclipseLink-3002] (Eclipse Persistence Services - 2.6.2.qualifier): org.eclipse.persistence.exceptions.ConversionException
【发布时间】:2018-02-19 08:52:53
【问题描述】:

我正在尝试在 Java Entity 类中获取表记录,其中一列定义为 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)

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

【问题讨论】:

    标签: java jpa jakarta-ee jpa-2.0 clob


    【解决方案1】:

    CLOB 必须是 char[] 而不是 byte[] ..... byte[] 用于 BLOB

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多