unsaved-value for id properties.

20 views
Skip to first unread message

Mattia Vitturi

unread,
Jun 22, 2011, 7:56:00 AM6/22/11
to ConfORM
Hello everyone!

I'm a little bit confused about how to set the unsaved-value policy
for the id properties. Is there any pattern to do it with conform?

My problem is that sometimes I need to use as primary key a Guid
created by myself

var id = new Guid("11111111-2222-3333-4444-555555555555");
var user = new User(id);
Session.Save(user);

...but, when I try to retrieve it from the db, I discover that it has
been persisted with a different id (and also the istance of user has
it changed). Taking a look at the xml of the hbm generated by my
mapping, I found out that the id is done in this way:

<class name="Test.User, Test, Version=0.1.0.0, Culture=neutral,
PublicKeyToken=null">
<id name="Id" type="Guid">
<generator class="guid.comb" />
</id>
<property name="Name" />
<property name="Surname" />
</class>

cause I put Orm.Patterns.PoidStrategies.Add(new
GuidOptimizedPoidPattern()); in my definition.
Referring to [1] I suspect I need to add the property unsaved-
value="id_value" to achieve what I need, but I have no idea how to do
it with ConfORM. Can someone point me to the right direction, please?

Thank you,
Mat.


[1]: http://knol.google.com/k/nhibernate-chapter-5-basic-o-r-mapping#5(2E)1(2E)4(2E)(C2)(A0)id

Fabio Maulo

unread,
Jun 22, 2011, 11:15:20 AM6/22/11
to codec...@googlegroups.com
guid and guid.comb mean that NH will manage them.
if you need something managed by you you have to use Assigned.
--
Fabio Maulo

Mattia Vitturi

unread,
Jun 24, 2011, 4:40:20 AM6/24/11
to ConfORM
That means I should manage by myself all the id or I can have a sort
of 'mixed' management?
Probably the ideal would be to use guid.comb as id generator for most
classes, and use assigned in those few cases where needed, if I
understood your point.

Thank you for your reply,
Mat.
> >http://knol.google.com/k/nhibernate-chapter-5-basic-o-r-mapping#5(2E)...
>
> --
> Fabio Maulo

Matteo Migliore

unread,
Jun 28, 2011, 4:23:24 PM6/28/11
to codec...@googlegroups.com
You can set the type of the key strategy assignment that you prefer for each entity using the mapper.Class<T> method.
Reply all
Reply to author
Forward
0 new messages