Hibernate class type resistance

I have an outdated table with compound keys that map to three other tables, since this table has other attributes in it, since it is not a simple mapping table, I cannot use a many-to-many solution to display this.

The following is what I did:

<class name="classA" table="A"> <composite-id name="ID" class="AKey"> <key-many-to-one name="Id_one" class="One" column="Id_one" /> <key-many-to-one name="Id_two" class="Two" column="Id_two" /> <key-many-to-one name="Id_three" class="Three" column="Id_three" /> </composite-id> 

AKey is just a structure that contains three identifiers, and Id_one, Id_two and Id_three are defined as int in the corresponding class.

 public struct Akey { public int Id_one { get; set; } public int Id_two { get; set; } public int Id_three { get; set; } } 

This compiles fine, but when I try to run it, it gives me an error message:

NHibernate.QueryException: type mismatch in NHibernate.Criterion.SimpleExpression: expected type identifier AKey, actual type System.Int32

Please report what I did wrong or missed.

Thanks a bunch!

+2
nhibernate composite-key
source share
1 answer

If you are going to use key-many-to-one, you must put the class:

 public class Akey { public virtual One One {get; set;} public virtual Two Two {get; set;} public virtual Three Three {get; set;} } 

Otherwise, if you need an identifier, you simply map it as properties of class A:

  <composite-id> <key-property name="Id_one" column="Id_one" /> <key-property name="Id_two" column="Id_two" /> <key-property name="Id_three" column="Id_three" /> </composite-id> 

.

 public class classA { public virtual int Id_one {get; set;} public virtual int Id_two {get; set;} public virtual int Id_three {get; set;} // ... rest of props ... } 

Or as compound as you have:

  <composite-id name="ID" class="AKey"> <key-property name="Id_one" column="Id_one" /> <key-property name="Id_two" column="Id_two" /> <key-property name="Id_three" column="Id_three" /> </composite-id> 

.

 public class AKey { public virtual int Id_one {get; set;} public virtual int Id_two {get; set;} public virtual int Id_three {get; set;} } public class classA { public virtual AKey ID {get; set;} // ... rest of props ... } 

Finally...

  <composite-id> <key-many-to-one name="Id_one" class="One" column="Id_one" /> <key-many-to-one name="Id_two" class="Two" column="Id_two" /> <key-many-to-one name="Id_three" class="Three" column="Id_three" /> </composite-id> 

.

 public class classA { public virtual One One {get; set;} public virtual Two Two {get; set;} public virtual Three Three {get; set;} // ... rest of props ... } 

The transition to whether it is possible to use a structure because I am not competent in them in C #.

+5
source share

All Articles