-->
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.  [ 12 posts ] 
Author Message
 Post subject: Storing blobs/files with OGM
PostPosted: Tue Mar 17, 2015 8:30 am 
Newbie

Joined: Mon Feb 23, 2015 3:53 pm
Posts: 8
Hi,

Regardless of whether it is a bad way, I'm interested in looking whether it is possible to store blobs/files with Hibernate OGM for MongoDB?
I heard there is a ''GridFS'' for MongoDB, but is it still possible to use this with Hibernate OGM?

Thanks!


Top
 Profile  
 
 Post subject: Re: Storing blobs/files with OGM
PostPosted: Wed Mar 18, 2015 3:39 am 
Hibernate Team
Hibernate Team

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

Yes, you can store blobs through Hibernate OGM. Just model it as a byte array and add @Lob:

Code:
@Lob
private byte[] lob;


This will be stored as a BinData field in MongoDB. But you need to be aware of the size limit for documents in MongoDB (16 MB).

Hibernate OGM does not support GridFS at this point; It might be an interesting way to store the "overflow" of large entities.

Hth,

--Gunnar

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


Top
 Profile  
 
 Post subject: Re: Storing blobs/files with OGM
PostPosted: Thu Mar 19, 2015 5:04 am 
Newbie

Joined: Mon Feb 23, 2015 3:53 pm
Posts: 8
Always appreciate it Gunnar! Thanks for the information.

I will try to work-around the problem and see how to still make use of GridFS while at the same time using Hibernate OGM. ;)


Top
 Profile  
 
 Post subject: Re: Storing blobs/files with OGM
PostPosted: Fri Mar 20, 2015 4:09 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I think we we end up working on custom user Types, we need to look at this use case as well. i.e. allow people to use the GridFS API.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Storing blobs/files with OGM
PostPosted: Fri Mar 20, 2015 4:12 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Actually, maybe we should offer native GridFS support via a MongoDB specific annotation. Can you open a JIRA? If you are super motivated, you can even give it a try. I don't think it would be too hard and we can guide you. Most of the work will be in one or two methods of MongoDBDialect.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Storing blobs/files with OGM
PostPosted: Sun Mar 29, 2015 10:53 am 
Newbie

Joined: Mon Feb 23, 2015 3:53 pm
Posts: 8
I'm terribly sorry for the late reply. Native GridFS support via a MongoDB specific annotation would be great.
I will open a Jira ticket soon and see what I can do! :)


Top
 Profile  
 
 Post subject: Re: Storing blobs/files with OGM
PostPosted: Mon Mar 30, 2015 7:59 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Cool :)

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Storing blobs/files with OGM
PostPosted: Thu Mar 03, 2016 5:17 am 
Newbie

Joined: Thu Nov 13, 2014 8:49 am
Posts: 9
Hi,

I am new to Hibernate OGM and currently working on a prototype to store images in a mongodb database. I am keen to know if GridFS support is available in any of the OGM versions? secondly could you please direct me towards an example to store it using @lob for image sizes below 4mb


Top
 Profile  
 
 Post subject: Re: Storing blobs/files with OGM
PostPosted: Thu Mar 03, 2016 7:28 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
We did not implement GridFS support yet sorry.
For storing your images something as simple as this should work

Code:
@Entity
public class Asset {
    @Id String id;
    @Lob
    byte[] data;
}


you will put your image bits into the byte[]

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Storing blobs/files with OGM
PostPosted: Thu Mar 03, 2016 10:29 am 
Newbie

Joined: Thu Nov 13, 2014 8:49 am
Posts: 9
Thank you.


Top
 Profile  
 
 Post subject: Re: Storing blobs/files with OGM
PostPosted: Thu Mar 03, 2016 2:04 pm 
Newbie

Joined: Thu Nov 13, 2014 8:49 am
Posts: 9
Hi

Using byte[], what is the maximum size of image that can be handled. As byte[] array can only be initialized using a int is the max size restricted to 32Kb?

e.g.
buffer = new byte[int] --- compiles
buffer = new byte[long] -- does not compile


Top
 Profile  
 
 Post subject: Re: Storing blobs/files with OGM
PostPosted: Fri Mar 04, 2016 12:12 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
No it's limited to 2 147 483 647 (2GB). 32k would be a short. But that's an interesting point I've never considered.

An alternative is to have a custom type to represent extremely long stream of bytes but we don't support custom types yet in Hibernate OGM.
A hacky solution is to represent your big long stream of byts as a Java Serializable object which we would convert to a stream of byte but I don't like this approach.

_________________
Emmanuel


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