我没有在我的模型上的数据类型中使用 BLOB,而是使用了 byte[].. 它将自动转换为数据库上的 blob..
您可以参考我的示例模型。
package models;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import org.joda.time.DateTime;
import play.db.jpa.GenericModel;
import com.google.gson.annotations.Expose;
@Entity
public class Memorandum extends GenericModel{
@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid2")
@Expose
public String id;
@Lob
public String details;
public String filename;
@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
public DateTime datePosted;
public byte[] attachment;
public String subject;
}
我的保存控制器
public static void save_memo(Memorandum memo,File attachment)
{
memo.datePosted = DateTime.now();
if(attachment!=null)
{
memo.attachment = IO.readContent(attachment);
memo.filename = attachment.getName();
}
memo.save();
index();
}
byte[] 在您的数据库中将采用 BLOB 格式。