These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: BLOB skipped on insert
PostPosted: Fri Apr 29, 2011 4:55 am 
Newbie

Joined: Thu Feb 12, 2009 10:00 am
Posts: 18
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.


Top
 Profile  
 
 Post subject: Re: BLOB skipped on insert
PostPosted: Wed May 04, 2011 4:20 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
remove @Basic(fetch = FetchType.LAZY) and try it again.

_________________
Dharmendra Pandey


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.