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.  [ 3 posts ] 
Author Message
 Post subject: Collection of unrelated objects
PostPosted: Wed Aug 16, 2006 11:49 am 
Beginner
Beginner

Joined: Thu Jun 29, 2006 12:32 pm
Posts: 22
Hibernate version: 1.2 alpha

Is it possible, using existing NHibernate mapping types, to have a collection of unrelated objects persist to the database? They can serialize their state to a single binary field. Ideally I'd like them to persist as XML (and I know there isn't a mapping for this), so binary serialization is ok to start with.

Cheers,

Stuart

_________________
--
Stuart Carnie


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 6:29 pm 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
(N)Hibernate is an object-relational mapper - which means it was designed to persist objects in a relational database. What you want to achieve is not persistence to a relational database so your scenario is not covered out of the box by hibernate.

cheers,
radu


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 6:43 pm 
Beginner
Beginner

Joined: Fri Jul 22, 2005 4:08 pm
Posts: 28
In Hibernate they've got a plugin mechanism where you can specify the persister for a specific property to convert value->db and db->value. I haven't found the same thing in NHibernate, so I made an ugly hack in my domain object. The SerializedValue property is only used by NHibernate to map to a binary(x) column:

Code:
        /// <summary>
        /// Gets or sets the value.
        /// </summary>
        /// <value>The value.</value>
        public object Value
        {
            get { return value; }
            set { this.value = value; }
        }

        /// <summary>
        /// Gets or sets the value.
        /// </summary>
        /// <value>The value.</value>
        private byte[] SerializedValue
        {
            get
            {
                if (Value == null)
                    return null;

                BinaryFormatter frmt = new BinaryFormatter();
                using (MemoryStream ms = new MemoryStream())
                {
                    frmt.Serialize(ms, Value);
                    ms.Close();
                    return ms.GetBuffer();
                }
            }
            set
            {
                if (value == null)
                    Value = null;

                BinaryFormatter frmt = new BinaryFormatter();
                using (MemoryStream ms = new MemoryStream(value))
                {
                    Value = frmt.Deserialize(ms);
                }
            }
        }


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