I want to upload a BLOB from the file explorer, but I'm a little new to uploading blobs, especially when using JPA(Java Persistance API).
I thought I'd show you some of my code and see if you can give me any ideas towards the right direction.
My entity class looks like this:
@Entity
@Table(name = "exampletable")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Blob1337.findByTestBlob", query = "SELECT e FROM Blob1337 e WHERE e.testBlob = :testBlob")})
@Column(name = "test_blob")
private Integer testBlob;
public Integer getTestBlob() {
return testBlob;
}
public void setTestBlob(Integer testBlob) {
this.testBlob = testBlob;
}
As you can see, I'm not sure what to use for BLOBs here, so it's an Integer for now.
My facade looks like this:
@PUT
@Path("{id}")
@Consumes({"application/json"})
public void edit(@PathParam("id") Integer id, Blob1337 entity) {
Blob1337 entityToMerge = find(id);
if (entity.getTestBlob() != null) {
entityToMerge.setTestBlob(entity.getTestBlob());
}
super.edit(entityToMerge);
}
How do I make my facade and entity class know that this is a BLOB? I want to be able upload this document through an ajax post, which should be pretty elementary if I'm correct.
Thank you! Any help is greatly appreciated!