I have this problem with handling BLOBS in my application. As the blobs are only ever set once and never changes I figured it be a good idea to declare them as non-updateble by adding updateble=false to the column annotation. This did provide me with a 10% performance improvement. However in some cases, in particular when ObjectA has more then one ObjectB associated then the BLOB is left empty. I don't understand why this happens. I enabled SQL logging in Hibernate and see both one insert and one update statement being executed. The insert statement correctly includes the DATA column which is also correctly excluded from the update statement. The end result is that the BLOB column is left empty.
The example code below is for illustration only as the actual example is quite a bit more complex.
Code:
@Entity
@Table
public class ObjectA implements Serializable {
@Id
@Column(name = "ID")
private int id;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "ObjectA", fetch = FetchType.LAZY)
@OrderBy("ORDER")
private List<ObjectB> bees= new ArrayList<ObjectB>();
@OneToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
@JoinColumn(name = "MASTEROBJECTB")
private ObjectB masterObjectB;
Code:
@Entity
@Table
public class ObjectB implements Serializable {
@Id
@Column(name = "ID")
private int id;
@Column(name = "DATA", updatable=false)
@Lob
@Basic(fetch = FetchType.LAZY)
private byte[] data;
Unfortunately BLOBs are not included in the debug statements and the BLOB column parameter is skipped.
Quote:
16:34:28,254 DEBUG [SQL]
insert
into
JS_CHANNELDESTS
(ID, DATA,...)
values
(?, ?,...)
16:34:28,278 TRACE [AbstractBatcher] preparing statement
16:34:28,300 TRACE [IntegerType] binding '1' to parameter: 1
16:34:28,339 TRACE [IntegerType] binding 'TEXT' to parameter: 3
16:34:28,339 TRACE [IntegerType] binding 'TEXT' to parameter: 4
16:34:28,419 DEBUG [AbstractBatcher] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
16:34:28,421 TRACE [AbstractBatcher] closing statement
I am using the following versions included with JBoss 4.2.3.
Hibernate EntityManager 3.2.1.GA
Hibernate Annotations 3.2.1.GA
Hibernate 3.2.4.sp1
Any suggestions on how to debug this further or resolve this.
Thanks in advance.