-->
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.  [ 7 posts ] 
Author Message
 Post subject: <joined-subclass> and Update/SaveOrUpdate
PostPosted: Wed Oct 03, 2007 9:04 am 
Beginner
Beginner

Joined: Fri Apr 27, 2007 11:50 am
Posts: 23
Hi Guys,

I have a base class of ContentItem and a class that extends this called StaticHtmlContent. I have a basic class mapping file for ContentItem and one for the StaticHtmlContent that uses joined-subclass to map the relationship with the ContentItem class.

When using the joined-subclass, using Save or SaveOrUpdate will create the StaticHtmlContent and add the data to the database. But if the StaticHtmlContent object already exists, when i call either SaveOrUpdate or just Update, i get no errors, but no data has been updated in the database.

Running sql profiler shows that no scripts were run.

Does anybody know a way to get this to work? Has anybody else ran into this issue?

Many thanks

Matt


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 04, 2007 1:48 am 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
Please post relevant mappings and code so we can help you more.
Off the top of my head, I'make sure you are calling .flush() somewhere in your code.

_________________
If this helped...please remember to rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 04, 2007 3:43 am 
Beginner
Beginner

Joined: Fri Apr 27, 2007 11:50 am
Posts: 23
ContentItem.hbm.xml

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
   <class name="Cuyahoga.Core.Domain.ContentItem, Cuyahoga.Core" table="Cuyahoga_contentitem">

      <cache usage="read-write" />

      <id name="Id" column="contentitemid" type="Int64" unsaved-value="-1">
         <generator class="native">
            <param name="sequence">Cuyahoga_contentitem_contentitemid_seq</param>
         </generator>
      </id>

      <property name="GlobalId" column="globalid" type="Guid" not-null="true" />
      <property name="WorkflowStatus" column="workflowstatus" not-null="true" />
      <property name="Title" column="title" type="String" length="255" not-null="true" />
      <property name="Summary" column="description" type="String" length="255" not-null="false" />
      <property name="Version" column="version" type="Int32" not-null="true" />
      <property name="Locale" column="locale" type="String" length="5" not-null="false" />
      <property name="CreatedAt" column="createdat" type="DateTime" not-null="true" />
      <property name="ModifiedAt" column="modifiedat" type="DateTime" not-null="true" />
      <property name="PublishedAt" column="publishedat" type="DateTime" not-null="false" />
      <property name="PublishedUntil" column="publishedUntil" type="DateTime" not-null="false" />
      <property name="UrlFormat" column="urlformat" type="String" length="255" not-null="true" />
      <many-to-one name="CreatedBy" class="Cuyahoga.Core.Domain.User, Cuyahoga.Core" column="createdby" not-null="true" />
      <many-to-one name="ModifiedBy" class="Cuyahoga.Core.Domain.User, Cuyahoga.Core" column="modifiedby" not-null="true" />
      <many-to-one name="PublishedBy" class="Cuyahoga.Core.Domain.User, Cuyahoga.Core" column="publishedby" not-null="false" />
      <many-to-one name="Section" class="Cuyahoga.Core.Domain.Section, Cuyahoga.Core" column="sectionid" not-null="true" />

   </class>
</hibernate-mapping>


StaticHtmlContent.hbm.xml

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
   <joined-subclass name="Cuyahoga.Modules.StaticHtml.StaticHtmlContent, Cuyahoga.Modules" extends="Cuyahoga.Core.Domain.ContentItem, Cuyahoga.Core" table="cm_statichtml">
      <key column="statichtmlid" />
      <property name="Content" column="content" type="StringClob" />
   </joined-subclass>
</hibernate-mapping>


The relivant code (stipped non related info)

Code:
namespace Cuyahoga.Core.DataAccess
{
    public class ContentItemDao<T> : IContentItemDao<T> where T : IContentItem
    {
        protected Type persistentType = typeof(T);
        protected ISessionManager _sessionManager;

        public ContentItemDao(ISessionManager sessionManager)
        {
            this._sessionManager = sessionManager;
        }


        protected ISession GetNewSession()
        {
            return this._sessionManager.OpenSession();
        }


        [Transaction(TransactionMode.Requires)]
        public T Save(T entity)
        {
            this.GetNewSession().Save(entity);
            return entity;
        }


        [Transaction(TransactionMode.Requires)]
        public T SaveOrUpdate(T entity)
        {
            this.GetNewSession().SaveOrUpdate(entity);
            return entity;
        }

    }
}


Debugging this (putting a breakpoint in the SaveOrUpdate method) it is definatley reached and stepping through it seems to run ok, but the SaveOrUpdate method at this.GetNewSession().SaveOrUpdate(entity); just doesn't do anything. No error, but no saved data either.

Let me know if there is anything else you'd like to know. Your help is much appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 04, 2007 4:13 am 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
Remember that the call to SaveOrUpdate does NOT persist data. It simply adds the entity to the current IdentityMap/UnitOfWork mechanism inside NHibernate. The terminology is admittedly confusing.

Are you making a call to Session.Flush() somewhere? (like in the EndRequest event)? If not that is what the problem is. You must flush the session at some point to persist your data/changes. Check the transaction scheme you are using (is that ATM?) and make sure at some point the Session.Transaction commits or a Session.Flush happens.

_________________
If this helped...please remember to rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 04, 2007 5:54 am 
Beginner
Beginner

Joined: Fri Apr 27, 2007 11:50 am
Posts: 23
Hmm, i'm currently using the SessionWebModule from castle t handle the creation and disposal of the session, however looking into it's code, it doesn't actually flush or comit the open transactions.

[ See Here ]

I don't seem to be able to find anywhere else that calls a flush (Cuyahoga is an open source CMS, so I don't know how everything is implemented yet)

Based on this then, i may need to look into a custom handler to flush the session.

Is that what you would recomend?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 04, 2007 12:57 pm 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
It depends on what your strategy for transactions are and how you are consuming your data access stuff.
Personally, I use Ayende's Rhino Commons that has a Unit Of Work implementation making it very easy to work with once you get how to work with it. You can use svn to pull down the source here:
https://rhino-tools.svn.sourceforge.net/svnroot/rhino-tools/trunk

All that said, I know nothing about Cuyahoga but have a hard time believing there isn't something in there that doesn't commit the transaction or flush the session .
Sorry i can't help you more than that.

_________________
If this helped...please remember to rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 04, 2007 3:17 pm 
Beginner
Beginner

Joined: Fri Apr 27, 2007 11:50 am
Posts: 23
No worries man, thanks for helping me out this far. I'll get the guys on the Cuyahoga project to take a look at the problem and your recomendations and see what they say.

You've been a great help.

Many thanks

Matt


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