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.  [ 3 posts ] 
Author Message
 Post subject: problem using ICreteria
PostPosted: Sun Nov 18, 2007 11:22 am 
Newbie

Joined: Sun Nov 18, 2007 9:47 am
Posts: 4
Hibernate version:2.2

i have the following mapping file
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Tatweer.TietLibrary.Trading" assembly="TietLibrary">
  <class name="Instrument" table="tiet_instruments">
    <composite-id>
      <key-property name="Isin" />
      <key-property name="Symbol" />
      <key-property name="SecurityExchangeId" />
    </composite-id>
    <property name="Isin" column="isin">
      <column name="isin" sql-type="char(12)" not-null="true" />
    </property>
    <property name="Symbol" column="symbol">
      <column name="symbol" sql-type="varchar(16)" not-null="true" />
    </property>
    <property name="Currency" column="currency">
      <column name="currency" sql-type="varchar(8)" not-null="true" />
    </property>
    <property name="Name" column="name">
      <column name="name" sql-type="text" not-null="false" />
    </property>
    <property name="SecurityExchangeId" column="marketId">
      <column name="marketId" sql-type="integer" not-null="false" />
    </property>   
  </class>
</hibernate-mapping>


now i try to find an entry by isin and marketid

Code:
NHibernate.ICriteria c = session.CreateCriteria(typeof(Instrument));
c.Add(NHibernate.Expression.Expression.Eq("Isin", "xxx"));
c.Add(NHibernate.Expression.Expression.Eq("SecurityExchangeId", "1"));


and it dies:

Code:
0x0001: Kernel: Error starting strategy 'eur_usd.cur': 'Tatweer.TietLibrary.Database.AccessException: Error getting item
s. ---> NHibernate.ADOException: could not execute query
[ SELECT this_.Isin as Isin1_0_, this_.Symbol as Symbol1_0_, this_.SecurityExchangeId as Security3_1_0_, this_.isin as i
sin1_0_, this_.symbol as symbol1_0_, this_.currency as currency1_0_, this_.name as name1_0_, this_.marketId as marketId1
_0_ FROM tiet_instruments this_ WHERE this_.Isin = ? and this_.SecurityExchangeId = ? ]
Positional parameters:   0 xxx
  0 1
[SQL: SELECT this_.Isin as Isin1_0_, this_.Symbol as Symbol1_0_, this_.SecurityExchangeId as Security3_1_0_, this_.isin
as isin1_0_, this_.symbol as symbol1_0_, this_.currency as currency1_0_, this_.name as name1_0_, this_.marketId as marke
tId1_0_ FROM tiet_instruments this_ WHERE this_.Isin = ? and this_.SecurityExchangeId = ?] ---> MySql.Data.MySqlClient.M
ySqlException: Unknown column 'this_.SecurityExchangeId' in 'field list'


looks to them that it is not translating the property "Isin" to "isin" and "SecurityExchangeId" to "marketId"

so it tried

Code:
c.Add(NHibernate.Expression.Expression.Eq("isin", "xxx"));
c.Add(NHibernate.Expression.Expression.Eq("marketId", "1"));


but

Code:
0x0001: Kernel: Error starting strategy 'eur_usd.cur': 'Tatweer.TietLibrary.Database.AccessException: Error getting item
s. ---> NHibernate.QueryException: could not resolve property: isin of: Tatweer.TietLibrary.Trading.Instrument
   bei NHibernate.Persister.Entity.AbstractPropertyMapping.ThrowPropertyException(String propertyName) in C:\Dokumente u
nd Einstellungen\Sascha.Kiefer\Desktop\NHibernate-1.2.0.GA-src\src\NHibernate\Persister\Entity\AbstractPropertyMapping.c
s:Zeile 29.


now it does not find the property "isin"

any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 18, 2007 12:48 pm 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
Ok, you have a few problems here. First, you shouldn't map your properties twice. I assume its trying to just use the first mapping (key-property) and ignoring the second (property). Put the column in the key-property item and then remove the property tag for those items entirely. Now it will properly transcode your properties to the correct column.

Second, when you pass in a property to the ICriteria it needs to be the property name, not the field name, or column name. So when you say Isin is the property you need to use "Isin" and not "isin". NHibernate will then use the information from the key-property column attribute to determine what the matching column in the database is.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 19, 2007 2:44 am 
Newbie

Joined: Sun Nov 18, 2007 9:47 am
Posts: 4
thank you.
is working now.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.