I am trying to read an byte[]
image from database.
This is the first of my two entities:
@Entity
public class ReceivingInspection implements Serializable {
/**
* The id.
*/
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="RECEIVING_INSPECTION_ID")
private int id;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "receivingInspection")
private List<ReceivingInspectionImage> receivingInspectionImages;
// Constructors, getters, setters
}
And this is my second entity:
@Entity
public class ReceivingInspectionImage implements Serializable {
@EJB
private ImageService imageService;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="RECEIVING_INSPECTION_IMAGE_ID")
private int id;
@Lob @Basic(fetch = FetchType.LAZY)
@Column(length=16777000)
private byte[] image;
@ManyToOne(fetch = FetchType.LAZY)
private ReceivingInspection receivingInspection;
public byte[] getImage() {
return imageService.getImage(id);
}
// Constructors, getters, setters
}
This is my DAO:
@PersistenceContext
private EntityManager em;
public byte[] getImage(int id) {
Query query = em
.createNativeQuery("SELECT * FROM RECEIVINGINSPECTIONIMAGE WHERE RECEIVING_INSPECTION_IMAGE_ID = ?");
query.setParameter(1, id);
ReceivingInspectionImage image = (ReceivingInspectionImage) query.getSingleResult();
return image.getImage();
}
When I am trying to deploy my application, I get a:
org.hibernate.MappingException: Could not determine type for: my.application.util.ImageService, at table: ReceivingInspectionImage, for columns: [org.hibernate.mapping.Column(imageService)]"}}
What could cause the problem? Is there a mistake in the way I am using Hibernate mapping?