Reputation: 123
I have a set of tables, with a .hbm.xml for each.
I tried to put in a named query but it would not compile. I moved the code to a CreateQuery and get.
DB_Portfolio is not mapped [select sum(p.Shares * s.Price) from DB_Portfolio p, DB_Securities s where p.AccountNumber = :accountNumber and p.CUSIP = s.Cusip]
The CreateQuery statement looks like.
IQuery queryBack = session.CreateQuery("select sum(p.Shares * s.Price) from DB_Portfolio p, DB_Securities s where p.AccountNumber = :accountNumber and p.CUSIP = s.Cusip");
queryBack.SetString("accountNumber", accountNumber);
return queryBack.UniqueResult<Decimal>();
I have in the DB_Portfolio .hbm.xml
<many-to-one name="Security" class="BDM_Controller.Source.ORM.DB_Securities, BDM_Controller" column="Cusip"/>
with a foreign key in Portofoio with security on Cusip.
What am I missing here?
Visual Studio 2008, NHibernate 2.1.0.4000, MS SqlServer 2005
Upvotes: 1
Views: 3734
Reputation: 3806
It looks to me that DB_Portfolio is your database table name, and not the class name. In your HQL query you should use the classname and not the database table name.
If "DB_Portfolio" actually is your classname: is the build action of your .hbm.xml file set to "embedded resource"? (Please do if it isn't).
This is a guess, since you did not post the DB_Portfolio mapping file. Please post the complete mapping file and the class definition if you want a more sophisticated answer.
Upvotes: 3
Reputation: 14471
I did calculated columns in the hibernate mapping file. See the formula in the example below:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="MyModule.DisciplineDTO, MyModule" table="Disciplines">
<id name="Id" column="DisciplineID" length="15">
<generator class="assigned"/>
</id>
<property name="Preference" formula="'TM.D.'+DisciplineID" update="false" insert="false"/>
</class>
</hibernate-mapping>
The update and insert attributes tell nHibernate this column is not to be used when constructing update and insert statements if this object is written to the database. You should specify the data type of the column as well.
Upvotes: 0