[英]problem with basic attributes java.sql.Blob
我有這個代碼
@Entity
@Table(name = "picture")
public class Picture implements Serializable {
@Id
@Column(name = "id")
@GeneratedValue
private int id;
@Column(name = "format", length = 8)
private String format;
@Basic(fetch = FetchType.LAZY)
@Column(name = "context", nullable = true, columnDefinition="mediumblob")
@Lob
private java.sql.Blob myBlobAttribute; // protected accessor and modifier
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "branch_fk", referencedColumnName = "id", nullable = false)
private Branch branch;
//Some setter and getter
我使用的是netbeans 6.7,在這個(private java.sql.Blob myBlobAttribute;)
它向我顯示了在線錯誤(private java.sql.Blob myBlobAttribute;)
但是代碼運行了,並且在數據庫中創建了圖片表! 它是一個真正的錯誤還是只是一個電子通知,我該如何解決? 錯誤消息是:
basic attributes can only be of the following types: java primitive types,wrapper of primitive types, String, java.math.bigInteger, java.math.BigDecimal, java,util.Date, java.util.Calendar, java.sql.Data, java.sql.TimeStamp, byte[], Byte[], char[], Character[], enums, or any Serializable type
NetBeans生成此警告的原因是,在使用java.sql.Blob
,您應該僅具有@Lob批注,而不能具有@Basic。
但是,在運行時,這聽起來像您的JPA實現通過忽略@Basic批注並認識到該列實際上是LOB來“幫助您”。 這就是為什么您的代碼可以工作的原因。 不同的JPA實現可能會失敗或以某種方式表現不同。
您的屬性類型是java.sql.Blob
,它是一個接口。
首先,為什么? 它不應該是一個字節數組嗎(大概是您存儲圖像的地方)?
其次,這就是NetBeans抱怨的原因-當您嘗試從該表中讀取內容時,Hibernate也會抱怨-他們沒有辦法知道要創建哪種實際類型將數據放入您的字段。
問題出在網上嗎?
@Lob
應該是@Blob
嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.