-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Session.Find throws Unique Index Exception Why ??
PostPosted: Tue Nov 28, 2006 5:49 pm 
Newbie

Joined: Tue Nov 28, 2006 5:44 pm
Posts: 2
Hi,

I am net to NHibernate, and I hava a read baisc/general question.

In my database (PostgreSQL), I have an unique index laying on the field transaktionsnummer which is located in the table payment.

I use the Find-Method of the Session class to query some objects:

ArrayList find = (ArrayList)Program.Session.Find("from payment where transaktionsnummer = ? ", transaktionsnummer, NHibernateUtil.Int32);

What now happens amazes me: I get an Db-Exception "duplicate key violates unique constraint uind_transaktionsnummer"

So my general question is: the Find-Method should be Read-Only, shouldn't it? How can a querying function trhow a uniqe constraint exception? It isn't supposed to write someting, or am I completely wrong?

thanks for any Hints,

Bernd


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 29, 2006 6:55 pm 
Beginner
Beginner

Joined: Wed Nov 29, 2006 5:33 pm
Posts: 28
Location: Chicago, IL
It would help to see the code for your Payment class and maybe the mapping file. I don't really know what PostgreSQL is trying to do here, but I will make some comments about the HQL that may or may not help.

When you write an HQL query, you are using classes and properties, and HQL is case sensitive. I am guessing that your payment class is actually Payment and possibly the transaktionsnummer(sic) property is cased more like TransaktionsNummer. I would start by changing your query to...
Code:
from Payment as p where p.TransaktionsNummer = ?


In the example I give, "Payment" is the class that I want to query from. "p" is an alias. "TransaktionsNummer" is a property in the Payment class. Both "Payment" and "TransaktionsNummer" should be cased the same as they are in your code files. The alias can be anything you want as long as it is consistent within the HQL query.

I don't know that this will solve your problem, but I hope it helps. If you still need help, try submitting your class and hbm.xml files. Also, enabling the NHibernate.SQL logger in the Log4Net logs will allow you to see the SQL that is being sent to the database so that you can get a better idea of what is happening.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.