-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate/JPA - Insert query with binary data parameter
PostPosted: Fri Feb 24, 2012 6:51 am 
Newbie

Joined: Wed Feb 22, 2012 9:10 am
Posts: 1
Hello,
is it possible to insert or update @Lob annotated fields with an hql query? I'm using Hibernate 4 + JPA 2, but issue occured also on earlier versions.

When I try the following:

Code:
public void mergeChunks(String fileName, File data) {
      Query query = getEntityManager()
            .createQuery(
                  "UPDATE TempFile SET dataHolder.data = dataHolder.data + :data WHERE fileName = :fileName");

      query.setParameter("fileName", fileName);
      try {
         query.setParameter("data",
               IOUtils.toByteArray(new FileInputStream(data)));
      } catch (IOException e) {
         LogFactory.getLog(TempFileService.class).error(e);
      }

      query.executeUpdate();
}


I get this error:

Code:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'set data=data+_binary'%PDF-1.6 %???? 3 0 obj<


I'm looking for something similiar to java.sql.PreparedStatement.setBinaryStream method. How to accomplish it with JPA??? I would be grateful for your help.

Cheers,
Wojciech


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

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.