views:

124

answers:

1

Yo

Quick q: are Nhibernate HiLo ids unique accross the DB?

The reason I ask is that we have multiple entities which have an image associated with them. On the client - I am simply storing these images in a folder using the enity ID as the name - am I going to trip over doing this?

w://

+3  A: 

It sounds a bit risky to count on that the ids are unique across the database.

If you have a separate next_hi value (separate row or column in the hibernate_unique_key table) for each entity your ids will not be unique. If you all entities share the same next_hi, you will still probably get duplicate ids if you use different max_lo values for different entities.

I guess that if you use a shared next_hi value for all entities and all entities have the same max_lo, then the ids should be unique, at the cost of greater id fragmentation. But you should probably take a closer look before putting any money on it.

Erik Öjebo
I ended up using a dictionary<string, guid> for a registry - the string portion being a url to the image on the network and the guid being the filename - each 'type' of image will have an id unique to it's coresponding entity and are stored in folders matching the discriminator so the id with the URL makes a unique key - the guid makes a nice unique name for the files :)
cvista