This is how I did it with 1 table only:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-
lazy="true" assembly="InExchange.Domain"
namespace="InExchange.Domain">
<class name="Invoice" table="ib_Invoice">
<id name="InvoiceId">
<generator class="native"></generator>
</id>
<!-- lazy load does not work with one-to-one relations -->
<many-to-one name="Data" class="InvoiceData" column="InvoiceId"
unique="true" insert="false" update="false" cascade="save-update"></
many-to-one>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-
lazy="true" assembly="InExchange.Domain"
namespace="InExchange.Domain">
<class name="InvoiceData" table="ib_Invoice">
<id name="InvoiceId">
<generator class="native"></generator>
</id>
<property name="Blob>
</class>
</hibernate-mapping>
Notice the insert="false" update="false" on the relation. I had to set
these attributes to avoid multiple inserts and strange behaivour in
general. Also, on first insert, you must set the Data property to
null, Then use ISession.Refresh() to let NH create a proxy object for
the Data property. After that you can update the blob field and do a
ISession.Flush().
Maybe there is a better way... ?
Regards,
Johannes
On 13 Nov, 13:07, "Stefan Sedich" <[EMAIL PROTECTED]> wrote:
> Thanks,
>
> I tried the one-to-one with 2 tables like so:
>
> Documents
> ---------
> Id
> Name
>
> DocumentFiles
> ---------------------
> Id --> Document.Id
> Data
>
> Mapping:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
> <class name="NHibernateDocumentTest.Document,
> NHibernateDocumentTest" table="Documents" lazy="false">
> <id name="Id" column="Id" type="integer">
> <generator class="native" />
> </id>
> <property name="Name" column="Name" type="string" />
> <one-to-one name="DocumentFile" cascade="all-delete-orphan" lazy="proxy"
> />
> </class>
> </hibernate-mapping>
>
> <?xml version="1.0" encoding="utf-8" ?>
> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
> <class name="NHibernateDocumentTest.DocumentFile,
> NHibernateDocumentTest" table="DocumentFiles" lazy="true">
> <id name="Id" column="Id" type="integer">
> <generator class="foreign">
> <param name="property">Document</param>
> </generator>
> </id>
> <property name="Data" column="Data" type="Byte[]" />
> <one-to-one name="Document" fetch="select" constrained="true" />
> </class>
> </hibernate-mapping>
>
> Classes:
>
> public class Document {
> public int Id { get; set; }
> public string Name { get; set; }
> public DocumentFile DocumentFile { get; set; }
> }
>
> public class DocumentFile {
> public virtual int Id { get; set; }
> public virtual Document Document { get; set; }
> public virtual byte[] Data { get; set; }
> }
>
> Now it will not lazy load the DocumentFile at all, it always loads it
> lazy does not work. Now if I change the Document mapping to use a many
> to one like so:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
> <class name="NHibernateDocumentTest.Document,
> NHibernateDocumentTest" table="Documents" lazy="false">
> <id name="Id" column="Id" type="integer">
> <generator class="native" />
> </id>
> <property name="Name" column="Name" type="string" />
> <many-to-one name="DocumentFile" Column="Id"
> cascade="all-delete-orphan" lazy="proxy" />
> </class>
> </hibernate-mapping>
>
> It works fine and lazy loads but I cannot insert any records anymore I
> get this error:
>
> "NHibernate.Id.IdentifierGenerationException: null id generated
> for:NHibernateDocumentTest.DocumentFile"
>
> Mmm this is more painful than I thought I assumed the one-to-one would
> work fine does this not support lazy loading?
>
> Cheers
>
>
>
> On Thu, Nov 13, 2008 at 8:57 PM, Tuna Toksöz <[EMAIL PROTECTED]> wrote:
> > I'll try, if time permits.
>
> > On Thu, Nov 13, 2008 at 12:10 PM, Stefan Sedich <[EMAIL PROTECTED]>
> > wrote:
>
> >> Thanks Tuna, not wanting to be spoon fed but have you got an example
> >> of this child class using the same table for me :)??
>
> >> On Thu, Nov 13, 2008 at 5:36 PM, Tuna Toksöz <[EMAIL PROTECTED]> wrote:
> >> > I think yes. My thinking was using a one-to-one relation but child class
> >> > may
> >> > also work.
>
> >> > On 11/13/08, Stefan Sedich <[EMAIL PROTECTED]> wrote:
>
> >> >> Mmm thanks I did see that now this suggestion off there:
>
> >> >> "Alternatively, assuming you want to do this as you have a large BLOB
> >> >> field (for example) an approach with existing NHibernate is to
> >> >> treat/map that field as part of another different (1-1) 'child' class
> >> >> (i.e. ignoring the fact that it is stored on the same table) and just
> >> >> lazy-load that child class."
>
> >> >> Is this possible to do? My idea is to just put the file in its own
> >> >> table and have a 1-1 mapping can this be done with 1 table as
> >> >> suggested?
>
> >> >> Cheers
>
> >> >> On Thu, Nov 13, 2008 at 4:53 PM, Tuna Toksöz <[EMAIL PROTECTED]> wrote:
> >> >> >http://jira.nhibernate.org/browse/NH-429
>
> >> >> > Are you looking for this? If so it looks it is still open.
>
> >> >> > On Thu, Nov 13, 2008 at 7:58 AM, codemonkey <[EMAIL PROTECTED]>
> >> >> > wrote:
>
> >> >> >> NH? I have googled forever and cannot find any
> >> >> >> info at all? My only option it seems is to use a seperate table to
> >> >> >> my
> >> >> >> image and map using a one-to-one with lazy set tot true.
>
> >> >> > --
> >> >> > Tuna Toksöz
>
> >> >> > Typos included to enhance the readers attention!
>
> >> >> --
> >> >> Stefan Sedich
> >> >> Software Developer
> >> >>http://weblogs.asp.net/stefansedich
>
> >> > --
> >> > Tuna Toksöz
>
> >> > Typos included to enhance the readers attention!
>
> >> --
> >> Stefan Sedich
> >> Software Developer
> >>http://weblogs.asp.net/stefansedich
>
> > --
> > Tuna Toksöz
>
> > Typos included to enhance the readers attention!
>
> --
> Stefan Sedich
> Software Developerhttp://weblogs.asp.net/stefansedich
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---