Mapping a Guid Id to String database column

267 views
Skip to first unread message

Colin Bowern

unread,
Mar 5, 2010, 1:05:19 PM3/5/10
to nhusers
I have an existing database schema where GUID's are being stored
inside an Oracle VARCHAR2(50 BYTE) field. In my domain object I am
looking to expose this as a Guid. In Fluent NHibernate I don't see an
IsCustomType method on the Id object so I am assuming that you can't
specify a custom type formatter. How would I make this mapping work?

Jason Dentler

unread,
Mar 7, 2010, 1:48:59 PM3/7/10
to nhu...@googlegroups.com
Try the uuid.hex POID generator.


--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.


Colin Bowern

unread,
Mar 10, 2010, 1:19:40 PM3/10/10
to nhusers
Thanks Jason! I tried that by setting the property in the model to a
Guid:

public virtual Guid Id { get; set; }

and in the map updated it to use the POID generator you suggested:

Id(x => x.Id, "SESSION_ID").GeneratedBy.UuidHex("B");

However, I get an exception from FluentNHibernate when I try to create
a session factory that says that my identity type must be a string.

at
FluentNHibernate.Mapping.IdentityGenerationStrategyBuilder.EnsureStringIdentityType()
at
FluentNHibernate.Mapping.IdentityGenerationStrategyBuilder.UuidHex(String
format)
at NHTest.SessionMap..ctor() in C:\\Projects\\Test\\NHTest\\NHTest\
\Maps\\SessionMap.cs:line 12

The problem centers around trying to get the field to map as a Guid on
the outside. I am thinking that I have to add an alternate access
route like a private field to make this scenario work. Thoughts?

On Mar 7, 1:48 pm, Jason Dentler <jasondent...@gmail.com> wrote:
> Try the uuid.hex POID generator.
>
>
>
> On Fri, Mar 5, 2010 at 12:05 PM, Colin Bowern <co...@bowern.com> wrote:
> > I have an existing database schema where GUID's are being stored
> > inside an Oracle VARCHAR2(50 BYTE) field. In my domain object I am
> > looking to expose this as a Guid.  In Fluent NHibernate I don't see an
> > IsCustomType method on the Id object so I am assuming that you can't
> > specify a custom type formatter.  How would I make this mapping work?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to nhu...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > nhusers+u...@googlegroups.com<nhusers%2Bunsu...@googlegroups.com­>


> > .
> > For more options, visit this group at

> >http://groups.google.com/group/nhusers?hl=en.- Hide quoted text -
>
> - Show quoted text -

Nexus

unread,
Mar 15, 2010, 11:00:59 AM3/15/10
to nhusers

Change :

public virtual Guid Id { get; set; }

==>

public virtual string Id { get; set; }

And you should be fine

Fabio Maulo

unread,
Mar 15, 2010, 10:57:28 PM3/15/10
to nhu...@googlegroups.com
The problem is not saving but uploading/parameters.
Your DataProvider has strictly rules about which is the expected RDBMS-Type for a Guid and, in general NH follows these rules.
For Oracle the Guid is:
DbType.Guid = RAW(16)

2010/3/5 Colin Bowern <co...@bowern.com>
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.




--
Fabio Maulo

Reply all
Reply to author
Forward
0 new messages