-->
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.  [ 6 posts ] 
Author Message
 Post subject: Save files - MongoDB
PostPosted: Tue Jan 27, 2015 11:54 am 
Newbie

Joined: Tue Jan 27, 2015 11:49 am
Posts: 1
Hello!

I'm using MongoDB with Hibernate OGM 4.1.1.
I'm trying to map an entity with a property containing binary data (a file).
I'm having problems with this property "image". I don't know, this is not mapped.
What am I doing wrong?
How should save this kind of data?

Code:
@Entity
@Table(name="photos")
public class Photo {

   @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Type(type = "objectid")
   private String id;
   private String user;
   private long creation_time;
   private String title;
   @ElementCollection
   private List<String> tags;
   private byte[] image;


Thanks for all.


Top
 Profile  
 
 Post subject: Re: Save files - MongoDB
PostPosted: Tue Jan 27, 2015 12:21 pm 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Hi,
could you give us some more information, please?

What's exactly is not working? Do you have an exception?


Top
 Profile  
 
 Post subject: Re: Save files - MongoDB
PostPosted: Wed Jan 28, 2015 6:34 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
@Davide, let's add a test in our test suite for byte[] anyways. I'm not certain we have a test for these.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Save files - MongoDB
PostPosted: Wed Jan 28, 2015 6:50 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi,

the byte[] is stored using MongoDB's BinData type (see https://github.com/hibernate/hibernate-ogm/blob/master/core/src/test/java/org/hibernate/ogm/backendtck/type/Bookmark.java#L201 for an example in our test suite). I thought that'd it require @Lob to be given, but it works for me with and without it. It'd be good to have a small test case demonstrating your issue (what kind of exception you get etc.)

Hth,

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: Save files - MongoDB
PostPosted: Wed Jan 28, 2015 7:26 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Ahah my bad, so we have a test :)

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Save files - MongoDB
PostPosted: Wed Jan 28, 2015 7:28 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
We have a test in place for byte[] so at the moment I don't know how to reproduce the error.
If he can give us more information about the error we might be able to solve the issue.

At the moment byte[] are store as Binary data in MongoDB, using the mongo CLI it should look something like:
Code:
"image" : BinData(0,"MTIzNDU=")


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.