Register  |  Login




Advertisement

Start Your Own Q&A Site

Create your own Q&A site easily, allowing you to quickly grow a new community around any subject matter or generate new organic traffic for your existing website.

Question

Status: Closed Points: 200 Time: 08:16 - Sep 29, 2008  

dustPuppy

Value cannot be null. Parameter name: fieldName error in NHibernate formula

Hi,

I am getting this error after I added a formula to a class: Value
cannot be null. Parameter name: fieldName
The formula is:
<property name="AnswersCount" formula="(SELECT COUNT(A.postid) FROM
Answerpost as A WHERE A.Userid = id)" insert="false" type="Int32" />
I suppose that it's because the formula returns null, but I can't find
a way to get around it.

I'd appreciate any help or directions...

Categories

Answer Discussion
Tutorials

 

nidhi

Date:: Sep 29, 2008

Time:: 18:31

Im currently using Hibernate with Spring in Java. Now I know you are using asp.net but the basic concepts should be the same.

The hibernate queries I use reference a class, and we have hibernate mapping (xml) files that map variables inside a class to a column in the table

It looks like you got normal sql, I wonder if you need to use it as Hibernate expects?

I do not use formula's like you do as Ive coded it with the class querying. XML files simply used to map (*.hbm.xml)

dustPuppy

Date:: Sep 30, 2008

Time:: 05:41

Hi Nidhi,
As far as I've read formulas have to be sql, hql won't work there.
But I figured out what the problem was. In this particular case I had created a sql query instead of using the hql, in order to get a particular result set of the user class that this formula is part of. So the sql was not adding the AnswersCount "virtual" property and that was why it was giving an error.

abcpaem

Date:: Nov 28, 2009

Time:: 03:55

Hi there, I have the same problem but I don't see a clear answer for the reason of this error, so after googling a little more, I found that the error occurs because you have the formula attribute set on any of the properties in the
mapping file, so it looks as if nhibernate ignores
the formula when you use CreateSqlQuery but then tries to access the derived column from the result set which creates the error. This seems to be a bug in Nhibernate and I haven't found a workaround.

To avoid this error, as dustyPuppy said, you must try to use a normal CreateQuery instead of CreateSQLQuery or remove the properties with the formula attribute in your mapping file, as there is not currently a patch for this issue.

Question Answered

This question has been closed, and points have been rewarded to the following experts:


dustPuppy: 200

You're welcome however to comment or give additional information or if you wish, you have the ability to write a Tutorial in the Tutorial Area.

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

No tutorials have been submitted yet. Want to be the first?

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top Experts

View More

Rank

Expert

Points

1.

nidhi

10354

2.

oracleofDelphi

6493

3.

rcastagna

5596

4.

LAGM

4848

5.

PeterNZ

3487

6.

gonzalo

2840

7.

Mason

2770

8.

jgivoni

2303

9.

xarcus

1820

10.

Anpanman

917

Become an Expert

Register today to share your knowledge with the community and be recognized and rewarded for your contributions.


Register Here




"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it



Language Options

English:

www.quomon.com

Español:

www.quomon.es