1

我正在尝试在我的 Java EE + OracleDB 应用程序中使用 EclipseLink 创建 ORM。问题是我不知道如何从数据库映射 ORDImage 类型。我尝试使用 @Struct 但没有成功。

我创建了两个@Struct 结构:

@Embeddable
@Struct(name = "ORDSource", fields = {"localData", "srcType", "srcLocation", "srcName", "updateTime", "local"})
public class OrdSourceStruct implements Serializable {
    private static final long serialVersionUID = 1L;

    @Lob
    @Basic
    @Column(name = "localData")
    private byte[] localData;
    @Column(name = "srcType")
    private String srcType;
    @Column(name = "srcLocation")
    private String srcLocation;
    @Column(name = "srcName")
    private String srcName;
    @Column(name = "updateTime")
    @Temporal(TemporalType.DATE)
    private Date updateTime;
    @Column(name = "local")
    private short sLocal;

    //getters and setters
    .......
}

第二个:

@Struct(name = "ORDImage", fields = {"source", "height", "width", "contentLength", "compressionFormat", "mimeType"})
public class OrdImageStruct implements Serializable {
    private static final long serialVersionUID = 1L;

    @Column(name = "source")
    private OrdSourceStruct source;
    @Column(name = "height")
    private Integer height;
    @Column(name = "width")
    private Integer width;
    @Column(name = "contentLength")
    private Integer contentLength;
    @Column(name = "fileFormat")
    private String fileFormat;
    @Column(name = "contentFormat")
    private String contentFormat;
    @Column(name = "compressionFormat")
    private String compressionFormat;
    @Column(name = "mimeType")
    private String mimeType;

    //getters and setters
    ...........
}

然后我尝试在实体中使用它们:

@Entity
@Table(name = "ZDJECIA")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Zdjecia.findAll", query = "SELECT z FROM Zdjecia z"),
    @NamedQuery(name = "Zdjecia.findById", query = "SELECT z FROM Zdjecia z WHERE z.id = :id")})
public class Zdjecia implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "ID")
    private Short id;
    @Column(name = "ZDJECIE")
    private OrdImageStruct zdjecie;
    @JoinColumn(name = "GRZYB", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private Grzyby grzyb;

    //getters and setters
    ...........
}

但是当我尝试显示 OrdImageStruct 类型的一些数据时,结果是:

Exception Description: The object [[Ljava.lang.Object;@2921ef9], of class [class
[Ljava.lang.Object;], from mapping 
[org.eclipse.persistence.mappings.DirectToFieldMapping[zdjecie-->ZDJECIA.ZDJECIE]] 
with descriptor [RelationalDescriptor(com.rmsbd.entities.Zdjecia --> 
[DatabaseTable(ZDJECIA)])], could not be converted to [class [B].

我究竟做错了什么?还有其他映射 ORDImage 的好方法吗?我想我可以处理任何其他 ORM 解决方案,所以它不必是 EclipseLink。对我来说最重要的是将这些 ORDImage 数据从数据库中获取到我的应用程序中。

4

0 回答 0