[nhusers] LockMode.FORCE with generated Version
Is there any plan for it to be supported? Currently it throws LockMode.Force is currently not supported for generated version properties. I can't see any technical reason why NH can't do it. One way I can think NH can do it is to issue the following sql: update entity set id = id where Version=@currentVersion and Id=@id; -- This will trigger DB to autoincrement the version select Version from entity where id = @id; -- This is to update the version of the entity in the current session Is there any chance for this to be supported in the future? Cheers -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhusers@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
Re: [nhusers] NH Bug: InvalidCastException within NH logging for composite-id
I didnt use one-to-one because I wanted to address my UserProfile by its User. One-to-one mapping in NH requires me to have an artificial integer to address my UserProfile entity. It's unnatural for the rest of my code. For example, my repository is now using int as its TKey. (e.g.. userProfileRepository.Get(user.Id), as well as all other methods that work on Id). The more natural way to approach this from my domain-centric view is for UserProfile to be identified by User (instead of by an obscure integer), which was the first thing I attempted to model, by placing an association as the Id of my entity. It seemed to be a very sensible and easy thing to do. On the DB side, I simply place an FK on my PK (one-to-one). On model-side, I simply have a User user property as my Id. On the NH side, it seemed that composite-id would be what I had to use. Wasn't quite successful. Now that I find that there's no clean way to map an association as your entity ID in NHibernate, I think I might have to revert back to one-to-one, but I'll have to refactor the rest of my code to work with my UserProfile entity using integer values. We do our domain modelling using a model-first approach, and try to get NH to work out the mapping to fit the model, rather than modelling the domain to fit NH mapping. That's how I got to this problem, and hence the need to refactor the code if I'm to revert back to using integer in order to have so-called cleaner NH mapping (using one-to-one). Might be easier to stick with composite-id and change my code into session.GetUserProfile(new UserProfile(user)); Having said that, crashing during the logging doesnt seem ideal to me. Logging module shouldn't really cause an exception. On Sat, Jan 8, 2011 at 8:12 PM, José F. Romaniello jfromanie...@gmail.comwrote: Session.Get for composite ids work as you said (with a full entity). There is another approach for composite ids, using a class for the id, a component, in that case get expect an instance of the component type. Where did you read about an anonymous type? You are wrong about the composite id and you are wrong about using a many to one. You DONT have many profiles for a user, you have only one, thus it is a one-to-one association (by pk) perfectly supported by nhibernate. Composite ids are composite, it is not right having one column. 2011/1/8, Hendry Luk hendrym...@gmail.com: That's because composite-id is the only way to make many-to-one association on your ID. There's no other way. You are allowed to have one or more properties as your composite-id. So one property is completely a valid mapping. What's invalid here is apparently the way I retrieve the instance, it had a semantic error. The correct way to get the object is: session.GetUserProfile(new UserProfile{Id = user}); Unfortunately the following code doesnt work either (it fails during the logging attempt): session.GetUserProfile(new {Id = user}); You have to construct an actual fullblown UserProfile entity to represent your ID solely for querying purpose. Similarly, if you have 2 properties under your composite-id, you can't do this either: session.GetUserProfile(new {Id1 = a, id2 = b}); That will throw an error during logging too. You always have to instantiate your entity. I havent' had a chance to investigate if this error is just a logging problem during the debug-mode, and whether it will actually work just fine in the production-mode (non-debug). Cheers, and so yes I have managed to get that working by instantiating a dummy instance of my entity for every call to GetById, which is not optimal but it works. On Fri, Jan 7, 2011 at 10:24 PM, José F. Romaniello jfromanie...@gmail.comwrote: I didn't go further on reading this message after i saw the mapping. Composite-id means composite-id, multiples columns are part of the PK and you have *only one.* The weird part of this, is that I'm sure you have read somewhere how bad are composite ids, however you have a pretty common case of one-to-one by primary key, that is very well supported by nhbiernate and you are trying to map it as a composite id. Read the section of one-to-one mapping, http://nhforge.org/doc/nh/en/index.html#mapping-declaration-onetoone you need to use generator class=foreign on UserProfile id as described there. 2011/1/7 Hendry Luk hendrym...@gmail.com Hello, How does one go about reporting a new bug in NH jira? I encountered the following issue. ?xml version=1.0 encoding=utf-8 ? hibernate-mapping xmlns=urn:nhibernate-mapping-2.2 assembly=MyDomain namespace=MyDomain.Model class name=UserProfile composite-id key-many-to-one name=Id column=UserId class=User / /composite-id /class /hibernate-mapping session.GetUserProfile(user); During debug-mode
Re: [nhusers] NH Bug: InvalidCastException within NH logging for composite-id
## Errata... I didnt use one-to-one because I wanted to identify my UserProfile by its User. One-to-one mapping in NH requires me to have an artificial integer to identify my UserProfile entity. It's just unnatural for the rest of my code. For example, my repository would therefore have to use int as its TKey. (e.g.. userProfileRepository.Get(user.Id), as well as all other methods that work on Id). The more natural way to approach this from my domain-centric view is for UserProfile to be identified by User (instead of by an obscure integer), which was the first thing I attempted to model, by placing an association as the Id of my entity. It seemed to be a very sensible and easy thing to do. On the DB side, I simply place an FK on my PK (one-to-one). On model-side, I simply have a User user property as my Id. On the NH side, it seemed that composite-id would be what I had to use. Wasn't quite successful. Now that I find that there's no clean way to map an association as your entity ID in NHibernate, I think I might have to revert back to one-to-one, but I'll have to refactor the rest of my code to work with my UserProfile entity using integer values. We do our domain modelling using a model-first approach, and try to get NH to work out the mapping to fit the model, rather than modelling the domain to fit NH mapping. That's how I got to this problem, and hence the need to refactor the code if I'm to revert back to using integer in order to have so-called cleaner NH mapping (using one-to-one). Might be easier to stick with composite-id and change my code into session.GetUserProfile(new UserProfile(user)); Having said that, crashing during the logging doesnt seem ideal to me. Logging module shouldn't really cause an exception. On Sat, Jan 8, 2011 at 8:12 PM, José F. Romaniello jfromanie...@gmail.comwrote: Session.Get for composite ids work as you said (with a full entity). There is another approach for composite ids, using a class for the id, a component, in that case get expect an instance of the component type. Where did you read about an anonymous type? You are wrong about the composite id and you are wrong about using a many to one. You DONT have many profiles for a user, you have only one, thus it is a one-to-one association (by pk) perfectly supported by nhibernate. Composite ids are composite, it is not right having one column. 2011/1/8, Hendry Luk hendrym...@gmail.com: That's because composite-id is the only way to make many-to-one association on your ID. There's no other way. You are allowed to have one or more properties as your composite-id. So one property is completely a valid mapping. What's invalid here is apparently the way I retrieve the instance, it had a semantic error. The correct way to get the object is: session.GetUserProfile(new UserProfile{Id = user}); Unfortunately the following code doesnt work either (it fails during the logging attempt): session.GetUserProfile(new {Id = user}); You have to construct an actual fullblown UserProfile entity to represent your ID solely for querying purpose. Similarly, if you have 2 properties under your composite-id, you can't do this either: session.GetUserProfile(new {Id1 = a, id2 = b}); That will throw an error during logging too. You always have to instantiate your entity. I havent' had a chance to investigate if this error is just a logging problem during the debug-mode, and whether it will actually work just fine in the production-mode (non-debug). Cheers, and so yes I have managed to get that working by instantiating a dummy instance of my entity for every call to GetById, which is not optimal but it works. On Fri, Jan 7, 2011 at 10:24 PM, José F. Romaniello jfromanie...@gmail.comwrote: I didn't go further on reading this message after i saw the mapping. Composite-id means composite-id, multiples columns are part of the PK and you have *only one.* The weird part of this, is that I'm sure you have read somewhere how bad are composite ids, however you have a pretty common case of one-to-one by primary key, that is very well supported by nhbiernate and you are trying to map it as a composite id. Read the section of one-to-one mapping, http://nhforge.org/doc/nh/en/index.html#mapping-declaration-onetoone you need to use generator class=foreign on UserProfile id as described there. 2011/1/7 Hendry Luk hendrym...@gmail.com Hello, How does one go about reporting a new bug in NH jira? I encountered the following issue. ?xml version=1.0 encoding=utf-8 ? hibernate-mapping xmlns=urn:nhibernate-mapping-2.2 assembly=MyDomain namespace=MyDomain.Model class name=UserProfile composite-id key-many-to-one name=Id column=UserId class=User / /composite-id /class /hibernate-mapping session.GetUserProfile
Re: [nhusers] NH Bug: InvalidCastException within NH logging for composite-id
Which brings me to this question: Is there any way to have association as your primary key? E.g. something that allows you to say session.Add(new UserProfile(user)), and session.GetUserProfile(user)? Cheers On Mon, Jan 10, 2011 at 11:02 AM, Hendry Luk hendrym...@gmail.com wrote: ## Errata... I didnt use one-to-one because I wanted to identify my UserProfile by its User. One-to-one mapping in NH requires me to have an artificial integer to identify my UserProfile entity. It's just unnatural for the rest of my code. For example, my repository would therefore have to use int as its TKey. (e.g.. userProfileRepository.Get(user.Id), as well as all other methods that work on Id). The more natural way to approach this from my domain-centric view is for UserProfile to be identified by User (instead of by an obscure integer), which was the first thing I attempted to model, by placing an association as the Id of my entity. It seemed to be a very sensible and easy thing to do. On the DB side, I simply place an FK on my PK (one-to-one). On model-side, I simply have a User user property as my Id. On the NH side, it seemed that composite-id would be what I had to use. Wasn't quite successful. Now that I find that there's no clean way to map an association as your entity ID in NHibernate, I think I might have to revert back to one-to-one, but I'll have to refactor the rest of my code to work with my UserProfile entity using integer values. We do our domain modelling using a model-first approach, and try to get NH to work out the mapping to fit the model, rather than modelling the domain to fit NH mapping. That's how I got to this problem, and hence the need to refactor the code if I'm to revert back to using integer in order to have so-called cleaner NH mapping (using one-to-one). Might be easier to stick with composite-id and change my code into session.GetUserProfile(new UserProfile(user)); Having said that, crashing during the logging doesnt seem ideal to me. Logging module shouldn't really cause an exception. On Sat, Jan 8, 2011 at 8:12 PM, José F. Romaniello jfromanie...@gmail.com wrote: Session.Get for composite ids work as you said (with a full entity). There is another approach for composite ids, using a class for the id, a component, in that case get expect an instance of the component type. Where did you read about an anonymous type? You are wrong about the composite id and you are wrong about using a many to one. You DONT have many profiles for a user, you have only one, thus it is a one-to-one association (by pk) perfectly supported by nhibernate. Composite ids are composite, it is not right having one column. 2011/1/8, Hendry Luk hendrym...@gmail.com: That's because composite-id is the only way to make many-to-one association on your ID. There's no other way. You are allowed to have one or more properties as your composite-id. So one property is completely a valid mapping. What's invalid here is apparently the way I retrieve the instance, it had a semantic error. The correct way to get the object is: session.GetUserProfile(new UserProfile{Id = user}); Unfortunately the following code doesnt work either (it fails during the logging attempt): session.GetUserProfile(new {Id = user}); You have to construct an actual fullblown UserProfile entity to represent your ID solely for querying purpose. Similarly, if you have 2 properties under your composite-id, you can't do this either: session.GetUserProfile(new {Id1 = a, id2 = b}); That will throw an error during logging too. You always have to instantiate your entity. I havent' had a chance to investigate if this error is just a logging problem during the debug-mode, and whether it will actually work just fine in the production-mode (non-debug). Cheers, and so yes I have managed to get that working by instantiating a dummy instance of my entity for every call to GetById, which is not optimal but it works. On Fri, Jan 7, 2011 at 10:24 PM, José F. Romaniello jfromanie...@gmail.comwrote: I didn't go further on reading this message after i saw the mapping. Composite-id means composite-id, multiples columns are part of the PK and you have *only one.* The weird part of this, is that I'm sure you have read somewhere how bad are composite ids, however you have a pretty common case of one-to-one by primary key, that is very well supported by nhbiernate and you are trying to map it as a composite id. Read the section of one-to-one mapping, http://nhforge.org/doc/nh/en/index.html#mapping-declaration-onetoone you need to use generator class=foreign on UserProfile id as described there. 2011/1/7 Hendry Luk hendrym...@gmail.com Hello, How does one go about reporting a new bug in NH jira? I encountered the following issue. ?xml version=1.0 encoding=utf-8 ? hibernate-mapping xmlns=urn:nhibernate-mapping
Re: [nhusers] NH Bug: InvalidCastException within NH logging for composite-id
I forgot to mention that I dont have any association between user and user.Profile. And by the way, UserProfile is hypothetical. In my specific domain case, the traversal is unidirectional from the other side. I think you misunderstood me. I did read your post, and more importantly I did *not* say session.Add(new UserProfile(user)) was impossible. If you continue on a bit further into the sentence, you'll find the actual question, which is how to identify UserProfile using its associated User (i.e. session.GetUserProfile(user)), instead of a simple arbitrary integer. Afterall, UserId is its PK, it makes sense to refer it by User, rather than int. The best way I could find is to implement it using session.GetUserProfile(new UserProfile(user)) with composite-id. I also read your post, and I'm very well familiar with both PK association and unique FK association in one-to-one mapping. But I dont understand how can that information help me in having association in my identity (instead of literal int values)? The only way I knew to have any association in your identity is by using composite-id, or am I wrong? Could you elaborate how I can achieve this using either PK or uniqueFK one-to-one? Did i miss anything? Thanks for your time replying. On Mon, Jan 10, 2011 at 11:39 AM, José F. Romaniello jfromanie...@gmail.com wrote: There isn't any artificial id on a one-to-one by pk. If you have the user, and you want his profile you simply do: user.Profile. If you have to go to a profile's repository to get the profile, that is *unnatural*. If you have a composite id with a single column, that is unnatural. If you have a many-to-one (profile to user), but you can't have many profiles, that is unnatural. If you think you need an artificial id, that is because you didn't read my message here nor in the blog post. I said nhibernate supports two kind of one-to-one scenarios, and you have one scenario where the relationship is in the PK. session.Add(new UserProfile(user)) - is perfectly possible, and i said so in my blog post... Again i think you didn't read it. 2011/1/9 Hendry Luk hendrym...@gmail.com Which brings me to this question: Is there any way to have association as your primary key? E.g. something that allows you to say session.Add(new UserProfile(user)), and session.GetUserProfile(user)? Cheers On Mon, Jan 10, 2011 at 11:02 AM, Hendry Luk hendrym...@gmail.comwrote: ## Errata... I didnt use one-to-one because I wanted to identify my UserProfile by its User. One-to-one mapping in NH requires me to have an artificial integer to identify my UserProfile entity. It's just unnatural for the rest of my code. For example, my repository would therefore have to use int as its TKey. (e.g.. userProfileRepository.Get(user.Id), as well as all other methods that work on Id). The more natural way to approach this from my domain-centric view is for UserProfile to be identified by User (instead of by an obscure integer), which was the first thing I attempted to model, by placing an association as the Id of my entity. It seemed to be a very sensible and easy thing to do. On the DB side, I simply place an FK on my PK (one-to-one). On model-side, I simply have a User user property as my Id. On the NH side, it seemed that composite-id would be what I had to use. Wasn't quite successful. Now that I find that there's no clean way to map an association as your entity ID in NHibernate, I think I might have to revert back to one-to-one, but I'll have to refactor the rest of my code to work with my UserProfile entity using integer values. We do our domain modelling using a model-first approach, and try to get NH to work out the mapping to fit the model, rather than modelling the domain to fit NH mapping. That's how I got to this problem, and hence the need to refactor the code if I'm to revert back to using integer in order to have so-called cleaner NH mapping (using one-to-one). Might be easier to stick with composite-id and change my code into session.GetUserProfile(new UserProfile(user)); Having said that, crashing during the logging doesnt seem ideal to me. Logging module shouldn't really cause an exception. On Sat, Jan 8, 2011 at 8:12 PM, José F. Romaniello jfromanie...@gmail.com wrote: Session.Get for composite ids work as you said (with a full entity). There is another approach for composite ids, using a class for the id, a component, in that case get expect an instance of the component type. Where did you read about an anonymous type? You are wrong about the composite id and you are wrong about using a many to one. You DONT have many profiles for a user, you have only one, thus it is a one-to-one association (by pk) perfectly supported by nhibernate. Composite ids are composite, it is not right having one column. 2011/1/8, Hendry Luk hendrym...@gmail.com: That's because composite-id is the only way to make many-to-one association on your ID
Re: [nhusers] NH Bug: InvalidCastException within NH logging for composite-id
Also note the reason why i got to this situation. We did not start our modelling by creating the DB tables and mapping first and try to fit our domain model around it. Instead, we create our domain-model first and all the domain code and the UI. Then finally try to make NH mapping to fit to the system, and finally generate the DB structure. So it's not like we are strongly against having int as the identity of our entity, we have no problem with it in general. It's just we have *already* modelled the entity with User object as its identity (instead of an integer), everything is already in place, and we were assuming that it would be quite straightforward for NH to map this id as an association. On Mon, Jan 10, 2011 at 3:07 PM, Hendry Luk hendrym...@gmail.com wrote: I forgot to mention that I dont have any association between user and user.Profile. And by the way, UserProfile is hypothetical. In my specific domain case, the traversal is unidirectional from the other side. I think you misunderstood me. I did read your post, and more importantly I did *not* say session.Add(new UserProfile(user)) was impossible. If you continue on a bit further into the sentence, you'll find the actual question, which is how to identify UserProfile using its associated User (i.e. session.GetUserProfile(user)), instead of a simple arbitrary integer. Afterall, UserId is its PK, it makes sense to refer it by User, rather than int. The best way I could find is to implement it using session.GetUserProfile(new UserProfile(user)) with composite-id. I also read your post, and I'm very well familiar with both PK association and unique FK association in one-to-one mapping. But I dont understand how can that information help me in having association in my identity (instead of literal int values)? The only way I knew to have any association in your identity is by using composite-id, or am I wrong? Could you elaborate how I can achieve this using either PK or uniqueFK one-to-one? Did i miss anything? Thanks for your time replying. On Mon, Jan 10, 2011 at 11:39 AM, José F. Romaniello jfromanie...@gmail.com wrote: There isn't any artificial id on a one-to-one by pk. If you have the user, and you want his profile you simply do: user.Profile. If you have to go to a profile's repository to get the profile, that is *unnatural*. If you have a composite id with a single column, that is unnatural. If you have a many-to-one (profile to user), but you can't have many profiles, that is unnatural. If you think you need an artificial id, that is because you didn't read my message here nor in the blog post. I said nhibernate supports two kind of one-to-one scenarios, and you have one scenario where the relationship is in the PK. session.Add(new UserProfile(user)) - is perfectly possible, and i said so in my blog post... Again i think you didn't read it. 2011/1/9 Hendry Luk hendrym...@gmail.com Which brings me to this question: Is there any way to have association as your primary key? E.g. something that allows you to say session.Add(new UserProfile(user)), and session.GetUserProfile(user)? Cheers On Mon, Jan 10, 2011 at 11:02 AM, Hendry Luk hendrym...@gmail.comwrote: ## Errata... I didnt use one-to-one because I wanted to identify my UserProfile by its User. One-to-one mapping in NH requires me to have an artificial integer to identify my UserProfile entity. It's just unnatural for the rest of my code. For example, my repository would therefore have to use int as its TKey. (e.g.. userProfileRepository.Get(user.Id), as well as all other methods that work on Id). The more natural way to approach this from my domain-centric view is for UserProfile to be identified by User (instead of by an obscure integer), which was the first thing I attempted to model, by placing an association as the Id of my entity. It seemed to be a very sensible and easy thing to do. On the DB side, I simply place an FK on my PK (one-to-one). On model-side, I simply have a User user property as my Id. On the NH side, it seemed that composite-id would be what I had to use. Wasn't quite successful. Now that I find that there's no clean way to map an association as your entity ID in NHibernate, I think I might have to revert back to one-to-one, but I'll have to refactor the rest of my code to work with my UserProfile entity using integer values. We do our domain modelling using a model-first approach, and try to get NH to work out the mapping to fit the model, rather than modelling the domain to fit NH mapping. That's how I got to this problem, and hence the need to refactor the code if I'm to revert back to using integer in order to have so-called cleaner NH mapping (using one-to-one). Might be easier to stick with composite-id and change my code into session.GetUserProfile(new UserProfile(user)); Having said that, crashing during the logging doesnt seem ideal to me. Logging module
Re: [nhusers] NH Bug: InvalidCastException within NH logging for composite-id
That's because composite-id is the only way to make many-to-one association on your ID. There's no other way. You are allowed to have one or more properties as your composite-id. So one property is completely a valid mapping. What's invalid here is apparently the way I retrieve the instance, it had a semantic error. The correct way to get the object is: session.GetUserProfile(new UserProfile{Id = user}); Unfortunately the following code doesnt work either (it fails during the logging attempt): session.GetUserProfile(new {Id = user}); You have to construct an actual fullblown UserProfile entity to represent your ID solely for querying purpose. Similarly, if you have 2 properties under your composite-id, you can't do this either: session.GetUserProfile(new {Id1 = a, id2 = b}); That will throw an error during logging too. You always have to instantiate your entity. I havent' had a chance to investigate if this error is just a logging problem during the debug-mode, and whether it will actually work just fine in the production-mode (non-debug). Cheers, and so yes I have managed to get that working by instantiating a dummy instance of my entity for every call to GetById, which is not optimal but it works. On Fri, Jan 7, 2011 at 10:24 PM, José F. Romaniello jfromanie...@gmail.comwrote: I didn't go further on reading this message after i saw the mapping. Composite-id means composite-id, multiples columns are part of the PK and you have *only one.* The weird part of this, is that I'm sure you have read somewhere how bad are composite ids, however you have a pretty common case of one-to-one by primary key, that is very well supported by nhbiernate and you are trying to map it as a composite id. Read the section of one-to-one mapping, http://nhforge.org/doc/nh/en/index.html#mapping-declaration-onetoone you need to use generator class=foreign on UserProfile id as described there. 2011/1/7 Hendry Luk hendrym...@gmail.com Hello, How does one go about reporting a new bug in NH jira? I encountered the following issue. ?xml version=1.0 encoding=utf-8 ? hibernate-mapping xmlns=urn:nhibernate-mapping-2.2 assembly=MyDomain namespace=MyDomain.Model class name=UserProfile composite-id key-many-to-one name=Id column=UserId class=User / /composite-id /class /hibernate-mapping session.GetUserProfile(user); During debug-mode, that will throw an InvalidCastException from ComponentType.ToLoggableString() method. It's fine during non debug-mode. The cause of that error, as I tracked down, is due to an attempt to get a string description from entity's ID (User object) by calling ComponentType.ToLoggableString(). Since we specify neither the property-name nor the class attribute in the composite-id element, nhibernate mistakenly uses EmbeddedComponentType of UserProfile class (instead of User class) in its attempt to GuessEntityMode of our User object. This will obviously fail, and the logger decides to throw exception on this situation (it should at least resort to other method.. afterall its sole purpose is just to print the string representation of the Id object). There's no appropriate workaround that I can think of that wouldn't compromise what I want to achieve. I can't specify class name in the composite-id element because NH will (inappropriately) complaint that this entity doesnt have an ID (because I set the class without the property-name). And obviously I can't specify the property-name because I want to have many-to-oneed complex type as my ID. I strongly believe this is a bug that needs to be fixed, and make the logging less intrusive. This issue has been raiseed in java's Hibernate before ( http://opensource.atlassian.com/projects/hibernate/browse/HHH-3148) Some ways to fix this that I can think of: not relying on tuplizer for logging at all, or may be resort to other way to produce the logging string in situations when no tuplizer is found (rather than throwing an exception). Cheers -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.comnhusers%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/nhusers?hl=en. -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.comnhusers%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/nhusers?hl=en. -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus
[nhusers] NH Bug: InvalidCastException within NH logging for composite-id
Hello, How does one go about reporting a new bug in NH jira? I encountered the following issue. ?xml version=1.0 encoding=utf-8 ? hibernate-mapping xmlns=urn:nhibernate-mapping-2.2 assembly=MyDomain namespace=MyDomain.Model class name=UserProfile composite-id key-many-to-one name=Id column=UserId class=User / /composite-id /class /hibernate-mapping session.GetUserProfile(user); During debug-mode, that will throw an InvalidCastException from ComponentType.ToLoggableString() method. It's fine during non debug-mode. The cause of that error, as I tracked down, is due to an attempt to get a string description from entity's ID (User object) by calling ComponentType.ToLoggableString(). Since we specify neither the property-name nor the class attribute in the composite-id element, nhibernate mistakenly uses EmbeddedComponentType of UserProfile class (instead of User class) in its attempt to GuessEntityMode of our User object. This will obviously fail, and the logger decides to throw exception on this situation (it should at least resort to other method.. afterall its sole purpose is just to print the string representation of the Id object). There's no appropriate workaround that I can think of that wouldn't compromise what I want to achieve. I can't specify class name in the composite-id element because NH will (inappropriately) complaint that this entity doesnt have an ID (because I set the class without the property-name). And obviously I can't specify the property-name because I want to have many-to-oneed complex type as my ID. I strongly believe this is a bug that needs to be fixed, and make the logging less intrusive. This issue has been raiseed in java's Hibernate before (http://opensource.atlassian.com/projects/hibernate/browse/HHH-3148) Some ways to fix this that I can think of: not relying on tuplizer for logging at all, or may be resort to other way to produce the logging string in situations when no tuplizer is found (rather than throwing an exception). Cheers -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
Re: [nhusers] Re: lazy = no-proxy does eager load in NH 3.0.0
I was under impression that you certainly don't. No-proxy means that your owner-entity's property will directly hit the DB and return your actual associated entity as soon as you access the getter, instead of returning the proxy of the associated-entity. On Thu, Jan 6, 2011 at 2:29 AM, Aaron Fischer pretzelfi...@gmail.comwrote: Nhibernate needs the proxy inorder to do lazy loading. -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.comnhusers%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/nhusers?hl=en. -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
Re: [nhusers] One-to-many to a subclass
Because joined-subclass can't be mixed with discriminator subclass within the same inheritance hierarchy. Like I mentioned in my post, I need to use discriminator-subclass because other subclasses do not have additional properties (only different behavior implementations). On Sat, Dec 4, 2010 at 12:01 AM, Fabio Maulo fabioma...@gmail.com wrote: why not joined-subclass ? On Thu, Dec 2, 2010 at 7:20 PM, Hendry Luk hendrym...@gmail.com wrote: Yes, in this case, because Employee has association to Company, and also other properties. Is there any other way to achieve that other than subclassjoin? On Thu, Dec 2, 2010 at 11:32 PM, Fabio Maulo fabioma...@gmail.comwrote: are you using subclass+join for some special reasons ? On Thu, Dec 2, 2010 at 6:45 AM, Hendry Luk hendrym...@gmail.com wrote: Hello, Is there any way to make one-many bag association from an entity to a subclass (with join)? Just an isolated example: class name=Person !-- blah blah -- discriminator column=PersonType / /class subclass name=Employee discriminator-value=Employee !-- blah blah -- join table=Emplooyee key column=PersonId / many-to-one name=Company column=CompanyId class=Company / /join /subclass class name=Company !-- blah blah -- bag name=Employees key column=CompanyId /--- this fails one-to-many class=Employee / /bag /class That bag will fail because it will seek CompanyId under Person table, instead of from the Employee table, which is understantable. But my question is if it's possible to achieve what I am going for. I cannot use joined-subclass, because in my real case (NotificationPolicy base-class), most of the subclasses don't have additonal properties (only different behavior), hence discriminnator column is more appropriate. Only in certain subclass do I need to join with another table for additional properties, but in NHibernate I'm not allowed to mix subclass and joined-sublass on the same inheritance hierarchy. Does anyone have any solution or workaround to make the above example work? Thanks -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.comnhusers%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/nhusers?hl=en. -- Fabio Maulo -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.comnhusers%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/nhusers?hl=en. -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.comnhusers%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/nhusers?hl=en. -- Fabio Maulo -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.comnhusers%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/nhusers?hl=en. -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
[nhusers] One-to-many to a subclass
Hello, Is there any way to make one-many bag association from an entity to a subclass (with join)? Just an isolated example: class name=Person !-- blah blah -- discriminator column=PersonType / /class subclass name=Employee discriminator-value=Employee !-- blah blah -- join table=Emplooyee key column=PersonId / many-to-one name=Company column=CompanyId class=Company / /join /subclass class name=Company !-- blah blah -- bag name=Employees key column=CompanyId /--- this fails one-to-many class=Employee / /bag /class That bag will fail because it will seek CompanyId under Person table, instead of from the Employee table, which is understantable. But my question is if it's possible to achieve what I am going for. I cannot use joined-subclass, because in my real case (NotificationPolicy base-class), most of the subclasses don't have additonal properties (only different behavior), hence discriminnator column is more appropriate. Only in certain subclass do I need to join with another table for additional properties, but in NHibernate I'm not allowed to mix subclass and joined-sublass on the same inheritance hierarchy. Does anyone have any solution or workaround to make the above example work? Thanks -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
[nhusers] Re: One-to-many to a subclass
And oh, just to point out that I can perfectly call the following query with no problem: session.QueryEmployee.Where(x= x.Company == company); It works fine. But I cant find a way to associate that with the Company entity. (I.e. for Company.Employees bag to invoke that same query). On Thu, Dec 2, 2010 at 8:45 PM, Hendry Luk hendrym...@gmail.com wrote: Hello, Is there any way to make one-many bag association from an entity to a subclass (with join)? Just an isolated example: class name=Person !-- blah blah -- discriminator column=PersonType / /class subclass name=Employee discriminator-value=Employee !-- blah blah -- join table=Emplooyee key column=PersonId / many-to-one name=Company column=CompanyId class=Company / /join /subclass class name=Company !-- blah blah -- bag name=Employees key column=CompanyId /--- this fails one-to-many class=Employee / /bag /class That bag will fail because it will seek CompanyId under Person table, instead of from the Employee table, which is understantable. But my question is if it's possible to achieve what I am going for. I cannot use joined-subclass, because in my real case (NotificationPolicy base-class), most of the subclasses don't have additonal properties (only different behavior), hence discriminnator column is more appropriate. Only in certain subclass do I need to join with another table for additional properties, but in NHibernate I'm not allowed to mix subclass and joined-sublass on the same inheritance hierarchy. Does anyone have any solution or workaround to make the above example work? Thanks -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
Re: [nhusers] One-to-many to a subclass
Yes, in this case, because Employee has association to Company, and also other properties. Is there any other way to achieve that other than subclassjoin? On Thu, Dec 2, 2010 at 11:32 PM, Fabio Maulo fabioma...@gmail.com wrote: are you using subclass+join for some special reasons ? On Thu, Dec 2, 2010 at 6:45 AM, Hendry Luk hendrym...@gmail.com wrote: Hello, Is there any way to make one-many bag association from an entity to a subclass (with join)? Just an isolated example: class name=Person !-- blah blah -- discriminator column=PersonType / /class subclass name=Employee discriminator-value=Employee !-- blah blah -- join table=Emplooyee key column=PersonId / many-to-one name=Company column=CompanyId class=Company / /join /subclass class name=Company !-- blah blah -- bag name=Employees key column=CompanyId /--- this fails one-to-many class=Employee / /bag /class That bag will fail because it will seek CompanyId under Person table, instead of from the Employee table, which is understantable. But my question is if it's possible to achieve what I am going for. I cannot use joined-subclass, because in my real case (NotificationPolicy base-class), most of the subclasses don't have additonal properties (only different behavior), hence discriminnator column is more appropriate. Only in certain subclass do I need to join with another table for additional properties, but in NHibernate I'm not allowed to mix subclass and joined-sublass on the same inheritance hierarchy. Does anyone have any solution or workaround to make the above example work? Thanks -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.comnhusers%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/nhusers?hl=en. -- Fabio Maulo -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.comnhusers%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/nhusers?hl=en. -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
[nhusers] Map (dictionary) in NH3
Hello, Has anyone tried Map (dictionary) element on NH3x? I haven't tried with NH2, but the following hbm file is rejected by NHibernate due to xsd validation (which shouldnt be. The hbm is validated successfully against the xsd within visual-studio). The hbm mapping file looks like this. class name=Person map name=SomeData key column=PersonId/ index column=AttributeName type=System.String/ element column=Attributevalue type=System.String/ /map /class The actual class definition is not relevant because nhibernate won't even accept this hbm mapping file at all due to the following xsd validation error: XML validation error: The element 'map' in namespace 'urn:nhibernate-mapping-2.2' cannot contain text. List of possible elements expected: 'map-key, composite-map-key, map-key-many-to-many, index, composite-index, index-many-to-many, index-many-to-any' in namespace 'urn:nhibernate-mapping-2.2'. System.Xml.Schema.XmlSchemaValidationException : The element 'map' in namespace 'urn:nhibernate-mapping-2.2' cannot contain text. List of possible elements expected: 'map-key, composite-map-key, map-key-many-to-many, index, composite-index, index-many-to-many, index-many-to-any' in namespace 'urn:nhibernate-mapping-2.2'. at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 340 at NHibernate.Cfg.Configuration.ValidationHandler(Object o, ValidationEventArgs args) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 1838 at System.Xml.Schema.XmlSchemaValidator.SendValidationEvent( XmlSchemaValidationException e, XmlSeverityType severity) at System.Xml.Schema.XmlSchemaValidator.SendValidationEvent(String code, String[] args) at System.Xml.Schema.XmlSchemaValidator.ValidateText(String elementStringValue, XmlValueGetter elementValueGetter) at System.Xml.Schema.XmlSchemaValidator.ValidateText(XmlValueGetter elementValue) at System.Xml.XsdValidatingReader.ProcessReaderEvent() at System.Xml.XsdValidatingReader.Read() at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace) at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc) at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at NHibernate.Cfg.Configuration.LoadMappingDocument(XmlReader hbmReader, String name) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 1778 at NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader, String name) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 1813 at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 630 at NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 668 at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 761 at NHibernate.Cfg.Configuration.AddAssembly(String assemblyName) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 744 at NHibernate.Cfg.Configuration.DoConfigure(ISessionFactoryConfiguration factoryConfiguration) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 1539 at NHibernate.Cfg.Configuration.Configure(XmlReader textReader) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 1509 at NHibernate.Cfg.Configuration.Configure(String fileName, Boolean ignoreSessionFactoryConfig) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 1431 at NHibernate.Cfg.Configuration.Configure(String fileName) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 1416 at NHibernate.Cfg.Configuration.Configure() in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 1402 Anyone has had this problem? I searched in the web and found that this exact hbm should work in previous version of NH, but not in the current release i'm using. Cheers -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
Re: [nhusers] one-to-one and cascade=all,delete-orphan
I think this is asked very frequently (including by me, just a couple weeks ago), and very little reply, but it's safe to say that it's still unsuported till date, and possibly will never be. Currently the workaround I use has always been mapping to a one-to-many private list field, and have your setter/getter to access the first item in that list. I.e. private readonly IListSomething list = new ListSomething(); public Something Property{ get{return list.First();} set{list.Clear(); if(value != null) list.Add(value);} } Then map that list field in the hbm using one-to-many On Tue, Nov 23, 2010 at 4:02 AM, gusgorman augustusgor...@yahoo.co.ukwrote: Hi, Was cascade=all,delete-orphan ever implemented in Nhibernate? It certainly wasn't at one point (see http://colinjack.blogspot.com/2008/03/nhibernate-gotchas-orphans-and-one-to.html ). many thanks, Jordan. -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.comnhusers%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/nhusers?hl=en. -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
[nhusers] Re: Map (dictionary) in NH3
Sorry guys... some dodgy empty-space-like character in the xml file apparently. Argh spent ages trying to debug this, including openning nh source-code, and upgrading our project's lib to NH3CR1. If you are interested, it was caused by a random character in the xml that looked like an innocent empty space (but it evidently wasn't). On Tue, Nov 23, 2010 at 2:53 PM, Hendry Luk hendrym...@gmail.com wrote: Hello, Has anyone tried Map (dictionary) element on NH3x? I haven't tried with NH2, but the following hbm file is rejected by NHibernate due to xsd validation (which shouldnt be. The hbm is validated successfully against the xsd within visual-studio). The hbm mapping file looks like this. class name=Person map name=SomeData key column=PersonId/ index column=AttributeName type=System.String/ element column=Attributevalue type=System.String/ /map /class The actual class definition is not relevant because nhibernate won't even accept this hbm mapping file at all due to the following xsd validation error: XML validation error: The element 'map' in namespace 'urn:nhibernate-mapping-2.2' cannot contain text. List of possible elements expected: 'map-key, composite-map-key, map-key-many-to-many, index, composite-index, index-many-to-many, index-many-to-any' in namespace 'urn:nhibernate-mapping-2.2'. System.Xml.Schema.XmlSchemaValidationException : The element 'map' in namespace 'urn:nhibernate-mapping-2.2' cannot contain text. List of possible elements expected: 'map-key, composite-map-key, map-key-many-to-many, index, composite-index, index-many-to-many, index-many-to-any' in namespace 'urn:nhibernate-mapping-2.2'. at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 340 at NHibernate.Cfg.Configuration.ValidationHandler(Object o, ValidationEventArgs args) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 1838 at System.Xml.Schema.XmlSchemaValidator.SendValidationEvent( XmlSchemaValidationException e, XmlSeverityType severity) at System.Xml.Schema.XmlSchemaValidator.SendValidationEvent(String code, String[] args) at System.Xml.Schema.XmlSchemaValidator.ValidateText(String elementStringValue, XmlValueGetter elementValueGetter) at System.Xml.Schema.XmlSchemaValidator.ValidateText(XmlValueGetter elementValue) at System.Xml.XsdValidatingReader.ProcessReaderEvent() at System.Xml.XsdValidatingReader.Read() at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace) at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc) at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at NHibernate.Cfg.Configuration.LoadMappingDocument(XmlReader hbmReader, String name) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 1778 at NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader, String name) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 1813 at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 630 at NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 668 at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 761 at NHibernate.Cfg.Configuration.AddAssembly(String assemblyName) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 744 at NHibernate.Cfg.Configuration.DoConfigure(ISessionFactoryConfiguration factoryConfiguration) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 1539 at NHibernate.Cfg.Configuration.Configure(XmlReader textReader) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 1509 at NHibernate.Cfg.Configuration.Configure(String fileName, Boolean ignoreSessionFactoryConfig) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 1431 at NHibernate.Cfg.Configuration.Configure(String fileName) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 1416 at NHibernate.Cfg.Configuration.Configure() in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs: line 1402 Anyone has had this problem? I searched in the web and found that this exact hbm should work in previous version of NH, but not in the current release i'm using. Cheers -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
[nhusers] Delete Orphans on 1-1 or M-1
Just wondering if that's still not supported, and if there's a plan for NH to support that scenario. I really think it should be. Cheers Hendry -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
[nhusers] Re: Delete Orphans on 1-1 or M-1
Just found a post from a couple months back that it's not supposed to be supported. Any reason why? Isn't it quite easy to implement? delete from child_table where id not in (select child_id from parent_table)? On Thu, Oct 21, 2010 at 2:57 PM, Hendry Luk hendrym...@gmail.com wrote: Just wondering if that's still not supported, and if there's a plan for NH to support that scenario. I really think it should be. Cheers Hendry -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
[nhusers] OOT: Hibernate User Group
Does anyone know any? I joined java-hibern...@googlegroups.com, but the only activities it has ever had seems to be its continous flow of job vacancy spams. There's no sign of humans life, unless they're all hibernating (pun clearly intended), and obviously there's no response to the question I posted. Cheers -- You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
[nhusers] Re: Linq Query ToLower
I also bumped into this problem (non-case-sensitive String.Contains() is a really common requirement), and still looking for a solution for this.. which apparently still produces the same exception in the recent release of NH-Linq. Any idea? Thanks On Tue, May 5, 2009 at 1:24 PM, Bryan Murphy bmurphy1...@gmail.com wrote: We're using Postgres and NHibernate 1.2, but are planning a migration to 2.0.x or 2.1.x soon. In one of my experiments, I'm trying to get a query to use the following index: CREATE INDEX users__index__username ON users(LOWER(username)); We haven't had any problems using these indexes with HQL, but we're experimenting with Linq 2 SQL. I can't figure out how to get NHibernate to call the database LOWER() function when writing a Linq query. Am I missing something? The query looks like this: from u in session.LinqUser() where u.EmailAddress.ToLower() == this.EmailAddress.ToLower() select u; And the exception I'm getting (v2.1.0alpha2) is: Unhandled Exception: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) at System.ThrowHelper.ThrowArgumentOutOfRangeException() at System.SZArrayHelper.get_Item[T](Int32 index) at System.Collections.ObjectModel.ReadOnlyCollection`1.get_Item(Int32 index) at NHibernate.Linq.Visitors.EntityExpressionVisitor.VisitMethodCall(MethodCallExpression expr) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.EntityExpressionVisitor.FindEntity(Expression expr, Boolean findFirst) at NHibernate.Linq.Visitors.EntityExpressionVisitor.RootEntity(Expression expr) at NHibernate.Linq.Visitors.BinaryCriterionVisitor.VisitMethodCall(MethodCallExpression expr) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.BinaryCriterionVisitor.GetBinaryCriteria(ICriteria rootCriteria, ISession session, BinaryExpression expr, ComparePropToValue comp arePropToValue, ComparePropToProp comparePropToProp, CompareValueToCriteria compareValueToCriteria, ComparePropToCriteria comparePropToCriteria) at NHibernate.Linq.Visitors.WhereArgumentsVisitor.VisitBinaryCriterionExpression(BinaryExpression expr) at NHibernate.Linq.Visitors.WhereArgumentsVisitor.VisitBinary(BinaryExpression expr) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.ExpressionVisitor.VisitLambda(LambdaExpression lambda) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.WhereArgumentsVisitor.VisitUnary(UnaryExpression expr) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.WhereArgumentsVisitor.GetCriterion(ICriteria rootCriteria, ISession session, Expression expression) at NHibernate.Linq.Visitors.RootVisitor.HandleWhereCall(MethodCallExpression call) at NHibernate.Linq.Visitors.RootVisitor.VisitMethodCall(MethodCallExpression expr) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateQueryTranslator.Translate(Expression expression, QueryOptions queryOptions) at NHibernate.Linq.NHibernateQueryProvider.Execute(Expression expression) at NHibernate.Linq.Query`1.System.Collections.IEnumerable.GetEnumerator() Thanks, Bryan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhusers@googlegroups.com To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~--~~~~--~~--~--~---
[nhusers] Re: Linq Query ToLower
I thought that would generate title LIKE'%a%'? (instead of LOWER(title) LIKE '%a%') On Mon, Jul 27, 2009 at 5:33 PM, Tuna Toksoz tehl...@gmail.com wrote: var query = from e in db.Employees where e.FirstName.Contains(a) select e; this works, regarding to string.contains. Tuna Toksöz Eternal sunshine of the open source mind. http://devlicio.us/blogs/tuna_toksoz http://tunatoksoz.com http://twitter.com/tehlike On Mon, Jul 27, 2009 at 10:25 AM, Hendry Luk hendrym...@gmail.com wrote: I also bumped into this problem (non-case-sensitive String.Contains() is a really common requirement), and still looking for a solution for this.. which apparently still produces the same exception in the recent release of NH-Linq. Any idea? Thanks On Tue, May 5, 2009 at 1:24 PM, Bryan Murphy bmurphy1...@gmail.comwrote: We're using Postgres and NHibernate 1.2, but are planning a migration to 2.0.x or 2.1.x soon. In one of my experiments, I'm trying to get a query to use the following index: CREATE INDEX users__index__username ON users(LOWER(username)); We haven't had any problems using these indexes with HQL, but we're experimenting with Linq 2 SQL. I can't figure out how to get NHibernate to call the database LOWER() function when writing a Linq query. Am I missing something? The query looks like this: from u in session.LinqUser() where u.EmailAddress.ToLower() == this.EmailAddress.ToLower() select u; And the exception I'm getting (v2.1.0alpha2) is: Unhandled Exception: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) at System.ThrowHelper.ThrowArgumentOutOfRangeException() at System.SZArrayHelper.get_Item[T](Int32 index) at System.Collections.ObjectModel.ReadOnlyCollection`1.get_Item(Int32 index) at NHibernate.Linq.Visitors.EntityExpressionVisitor.VisitMethodCall(MethodCallExpression expr) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.EntityExpressionVisitor.FindEntity(Expression expr, Boolean findFirst) at NHibernate.Linq.Visitors.EntityExpressionVisitor.RootEntity(Expression expr) at NHibernate.Linq.Visitors.BinaryCriterionVisitor.VisitMethodCall(MethodCallExpression expr) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.BinaryCriterionVisitor.GetBinaryCriteria(ICriteria rootCriteria, ISession session, BinaryExpression expr, ComparePropToValue comp arePropToValue, ComparePropToProp comparePropToProp, CompareValueToCriteria compareValueToCriteria, ComparePropToCriteria comparePropToCriteria) at NHibernate.Linq.Visitors.WhereArgumentsVisitor.VisitBinaryCriterionExpression(BinaryExpression expr) at NHibernate.Linq.Visitors.WhereArgumentsVisitor.VisitBinary(BinaryExpression expr) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.ExpressionVisitor.VisitLambda(LambdaExpression lambda) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.WhereArgumentsVisitor.VisitUnary(UnaryExpression expr) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.WhereArgumentsVisitor.GetCriterion(ICriteria rootCriteria, ISession session, Expression expression) at NHibernate.Linq.Visitors.RootVisitor.HandleWhereCall(MethodCallExpression call) at NHibernate.Linq.Visitors.RootVisitor.VisitMethodCall(MethodCallExpression expr) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateQueryTranslator.Translate(Expression expression, QueryOptions queryOptions) at NHibernate.Linq.NHibernateQueryProvider.Execute(Expression expression) at NHibernate.Linq.Query`1.System.Collections.IEnumerable.GetEnumerator() Thanks, Bryan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhusers@googlegroups.com To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nhusers
[nhusers] Re: Linq Query ToLower
Sorry, no joy.. Still exact same exception.. Cheers On Mon, Jul 27, 2009 at 5:35 PM, Tuna Toksoz tehl...@gmail.com wrote: can you retry your query like this: string emailAddress=his.EmailAddress.ToLower(); from u in session.LinqUser() where u.EmailAddress.ToLower() == emailAddress select u; Tuna Toksöz Eternal sunshine of the open source mind. http://devlicio.us/blogs/tuna_toksoz http://tunatoksoz.com http://twitter.com/tehlike On Tue, May 5, 2009 at 6:24 AM, Bryan Murphy bmurphy1...@gmail.comwrote: We're using Postgres and NHibernate 1.2, but are planning a migration to 2.0.x or 2.1.x soon. In one of my experiments, I'm trying to get a query to use the following index: CREATE INDEX users__index__username ON users(LOWER(username)); We haven't had any problems using these indexes with HQL, but we're experimenting with Linq 2 SQL. I can't figure out how to get NHibernate to call the database LOWER() function when writing a Linq query. Am I missing something? The query looks like this: from u in session.LinqUser() where u.EmailAddress.ToLower() == this.EmailAddress.ToLower() select u; And the exception I'm getting (v2.1.0alpha2) is: Unhandled Exception: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) at System.ThrowHelper.ThrowArgumentOutOfRangeException() at System.SZArrayHelper.get_Item[T](Int32 index) at System.Collections.ObjectModel.ReadOnlyCollection`1.get_Item(Int32 index) at NHibernate.Linq.Visitors.EntityExpressionVisitor.VisitMethodCall(MethodCallExpression expr) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.EntityExpressionVisitor.FindEntity(Expression expr, Boolean findFirst) at NHibernate.Linq.Visitors.EntityExpressionVisitor.RootEntity(Expression expr) at NHibernate.Linq.Visitors.BinaryCriterionVisitor.VisitMethodCall(MethodCallExpression expr) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.BinaryCriterionVisitor.GetBinaryCriteria(ICriteria rootCriteria, ISession session, BinaryExpression expr, ComparePropToValue comp arePropToValue, ComparePropToProp comparePropToProp, CompareValueToCriteria compareValueToCriteria, ComparePropToCriteria comparePropToCriteria) at NHibernate.Linq.Visitors.WhereArgumentsVisitor.VisitBinaryCriterionExpression(BinaryExpression expr) at NHibernate.Linq.Visitors.WhereArgumentsVisitor.VisitBinary(BinaryExpression expr) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.ExpressionVisitor.VisitLambda(LambdaExpression lambda) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.WhereArgumentsVisitor.VisitUnary(UnaryExpression expr) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.WhereArgumentsVisitor.GetCriterion(ICriteria rootCriteria, ISession session, Expression expression) at NHibernate.Linq.Visitors.RootVisitor.HandleWhereCall(MethodCallExpression call) at NHibernate.Linq.Visitors.RootVisitor.VisitMethodCall(MethodCallExpression expr) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateQueryTranslator.Translate(Expression expression, QueryOptions queryOptions) at NHibernate.Linq.NHibernateQueryProvider.Execute(Expression expression) at NHibernate.Linq.Query`1.System.Collections.IEnumerable.GetEnumerator() Thanks, Bryan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhusers@googlegroups.com To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~--~~~~--~~--~--~---
[nhusers] Re: Linq Query ToLower
Quite weirdly, this doesnt work too: u.EmailAddress.Equals(emailAddress, StringComparison.CurrentCultureIgnoreCase)) .. even though StringComparison.CurrentCultureIgnoreCase works perfectly with both StartsWith() and EndsWith() . And unfortunately, String.Contains() doesn't have overload that accepts StringComparison parameter. Cheers On Mon, Jul 27, 2009 at 6:01 PM, Hendry Luk hendrym...@gmail.com wrote: Sorry, no joy.. Still exact same exception.. Cheers On Mon, Jul 27, 2009 at 5:35 PM, Tuna Toksoz tehl...@gmail.com wrote: can you retry your query like this: string emailAddress=his.EmailAddress.ToLower(); from u in session.LinqUser() where u.EmailAddress.ToLower() == emailAddress select u; Tuna Toksöz Eternal sunshine of the open source mind. http://devlicio.us/blogs/tuna_toksoz http://tunatoksoz.com http://twitter.com/tehlike On Tue, May 5, 2009 at 6:24 AM, Bryan Murphy bmurphy1...@gmail.comwrote: We're using Postgres and NHibernate 1.2, but are planning a migration to 2.0.x or 2.1.x soon. In one of my experiments, I'm trying to get a query to use the following index: CREATE INDEX users__index__username ON users(LOWER(username)); We haven't had any problems using these indexes with HQL, but we're experimenting with Linq 2 SQL. I can't figure out how to get NHibernate to call the database LOWER() function when writing a Linq query. Am I missing something? The query looks like this: from u in session.LinqUser() where u.EmailAddress.ToLower() == this.EmailAddress.ToLower() select u; And the exception I'm getting (v2.1.0alpha2) is: Unhandled Exception: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) at System.ThrowHelper.ThrowArgumentOutOfRangeException() at System.SZArrayHelper.get_Item[T](Int32 index) at System.Collections.ObjectModel.ReadOnlyCollection`1.get_Item(Int32 index) at NHibernate.Linq.Visitors.EntityExpressionVisitor.VisitMethodCall(MethodCallExpression expr) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.EntityExpressionVisitor.FindEntity(Expression expr, Boolean findFirst) at NHibernate.Linq.Visitors.EntityExpressionVisitor.RootEntity(Expression expr) at NHibernate.Linq.Visitors.BinaryCriterionVisitor.VisitMethodCall(MethodCallExpression expr) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.BinaryCriterionVisitor.GetBinaryCriteria(ICriteria rootCriteria, ISession session, BinaryExpression expr, ComparePropToValue comp arePropToValue, ComparePropToProp comparePropToProp, CompareValueToCriteria compareValueToCriteria, ComparePropToCriteria comparePropToCriteria) at NHibernate.Linq.Visitors.WhereArgumentsVisitor.VisitBinaryCriterionExpression(BinaryExpression expr) at NHibernate.Linq.Visitors.WhereArgumentsVisitor.VisitBinary(BinaryExpression expr) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.ExpressionVisitor.VisitLambda(LambdaExpression lambda) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.WhereArgumentsVisitor.VisitUnary(UnaryExpression expr) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.WhereArgumentsVisitor.GetCriterion(ICriteria rootCriteria, ISession session, Expression expression) at NHibernate.Linq.Visitors.RootVisitor.HandleWhereCall(MethodCallExpression call) at NHibernate.Linq.Visitors.RootVisitor.VisitMethodCall(MethodCallExpression expr) at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp) at NHibernate.Linq.Visitors.NHibernateQueryTranslator.Translate(Expression expression, QueryOptions queryOptions) at NHibernate.Linq.NHibernateQueryProvider.Execute(Expression expression) at NHibernate.Linq.Query`1.System.Collections.IEnumerable.GetEnumerator() Thanks, Bryan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhusers@googlegroups.com To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.com For more
[nhusers] Re: Mapping 1 - [zero or 1] Relationship
Thanks for the reply. Is it possible to make a relationship on 2 columns without having subclasses? Because the whole point of this structure is that each address row/instance can be assigned as any type (home, work, billing), e.g.: same as above address checkbox. And regarding lazy load, I did some google and found out that lazy loading is NOT apparently supported for one-one relationship, particularly for non-mandatory one. And for the reason mentioned (nhibernate needs to know in advance whether the other side of the relation exists before assigning a proxy). Does this (still) hold true? Loading all addresses for each customer in a huge search can be really expensive. Does anyone has any trick or pointer to do lazy-load in one-to-one (or many to one) relationships in NH? Thanks On Fri, Feb 13, 2009 at 4:04 AM, Ben Scheirman subdigi...@gmail.com wrote: address_type is your discriminator column, then subclass Address for the various types. Perhaps there's a better way, but that should work. On Wed, Feb 11, 2009 at 8:36 PM, Hendry Luk hendrym...@gmail.com wrote: Hi there, I'm wondering how the scenario below can be mapped through NH. It's a legacy entity structure. public class Customer { public Address HomeAddress {get;set;} public Address WorkAddress {get; set;} public Address BillingAddress {get;set;} } Unfortunately, it's also mapped to legacy database structure, where we have an associative table: create table CUSTOMERS_ADDRESSES ( customer_id int, address_id int, address_type varchar(10) ) Where address_type holds 'HOME' or 'WORK' or 'BILLING'. I.e., for clarity, home-address is populated with this query: select * from ADDRESSES where address_id in (select address_id from CUSTOMERS_ADDRESSES where customer_id=? and address_type = 'HOME' How do we map this association in nhibernate mapping? And my real concern is about lazyload and nulls. Each of the addresses is optional and may therefore be null. And if we're to use lazy-load, they can never be null (instead, a proxy instance, which i suspect will throw ObjectNotFoundException when the actual loading kicks in). Any advice? Thanks Hendry --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhusers@googlegroups.com To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~--~~~~--~~--~--~---
[nhusers] Mapping 1 - [zero or 1] Relationship
Hi there, I'm wondering how the scenario below can be mapped through NH. It's a legacy entity structure. public class Customer { public Address HomeAddress {get;set;} public Address WorkAddress {get; set;} public Address BillingAddress {get;set;} } Unfortunately, it's also mapped to legacy database structure, where we have an associative table: create table CUSTOMERS_ADDRESSES ( customer_id int, address_id int, address_type varchar(10) ) Where address_type holds 'HOME' or 'WORK' or 'BILLING'. I.e., for clarity, home-address is populated with this query: select * from ADDRESSES where address_id in (select address_id from CUSTOMERS_ADDRESSES where customer_id=? and address_type = 'HOME' How do we map this association in nhibernate mapping? And my real concern is about lazyload and nulls. Each of the addresses is optional and may therefore be null. And if we're to use lazy-load, they can never be null (instead, a proxy instance, which i suspect will throw ObjectNotFoundException when the actual loading kicks in). Any advice? Thanks Hendry --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups nhusers group. To post to this group, send email to nhusers@googlegroups.com To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~--~~~~--~~--~--~---