-->
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: Several classes on same table in same Session
PostPosted: Mon Jan 14, 2008 8:48 am 
Newbie

Joined: Thu Jun 22, 2006 12:51 pm
Posts: 10
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: nHibernate 1.2.0.GA

Mapping documents:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">
  <class name="NHibernate.Test.SomeClassesOnTable.SomeClassesOnTableDigest, NHibernate.Test" table="SomeClassesOnTable">
    <id name="identifier" access="field" column="identifier" unsaved-value="-1" type="string" >
      <generator class="assigned" />
    </id>   
  </class>
</hibernate-mapping>


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">

Code:
  <class name="NHibernate.Test.SomeClassesOnTable.SomeClassesOnTableEntity, NHibernate.Test" table="SomeClassesOnTable">
    <id name="identifier" access="field" column="identifier" unsaved-value="-1" type="string" >
      <generator class="assigned" />
    </id>
    <property name="data" type="BinaryBlob" access="field" />
  </class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():

Code:
  [Test]
        public void Test()
            {
            using ( ISession s1 = OpenSession() )
                {
                ITransaction t1 = s1.BeginTransaction();
                SomeClassesOnTableDigest sb = s1.Get<SomeClassesOnTableDigest>("aaa"); //SessionImpl.nonExists collection now have EntityKey with SomeClassesOnTableDigest  type
                if ( sb == null )
                    {
                        SomeClassesOnTableEntity sb1 = s1.Get<SomeClassesOnTableEntity>("aaa");  //SessionImpl.nonExists collection now have EntityKey with SomeClassesOnTableEntity type
                    Assert.IsNull( sb1 );
                    sb1 = new SomeClassesOnTableEntity("aaa", new byte[] { 1, 2, 3, 4, 5 }); //SessionImpl.nonExists collection remove EntityKey with SomeClassesOnTableEntity type
                    s1.Save( sb1 );
                    }
                SomeClassesOnTableDigest result = s1.Get<SomeClassesOnTableDigest>("aaa");
                Assert.IsNotNull( result, "SessionImpl.nonExists collection still contains EntityKey with SomeClassesOnTableDigest  type. ");
                t1.Rollback();
                s1.Close();
                }
            }



Name and version of the database you are using: MSSQL 2005

Does this case supported?
If not, what is alternative? need need have something like lazy property, that have BIG binary data, and not want load it before it really need.


[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 14, 2008 10:48 am 
Beginner
Beginner

Joined: Tue Sep 04, 2007 12:36 pm
Posts: 23
Perhaps this is obvious but I wanted to make sure.

Is it OK to separate the BLOB in to a separate table with a many-to-one reference on the "Digest" table?

This way, the "Digest" object could lazily load the BLOB in a simple manner.

Another way would be the component mapping feature, where the blob is a component of the digest object
http://www.hibernate.org/hib_docs/nhibernate/html/components.html

Finally, Ayende has a solution for lazy property loading, but it is somewhat new:
http://www.ayende.com/Blog/archive/2007/08/26/Lazy-Property-Loading-In-NHibernate.aspx

I dont know if this makes your design ugly, but these options have potential to solve your problem in a simple way.[/url]

_________________
^^If this post helped you, make sure to rate it Thanks!


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.