-->
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: Query by Example et Object
PostPosted: Thu Aug 25, 2005 10:34 am 
Newbie

Joined: Wed Aug 10, 2005 8:07 am
Posts: 14
Bonjour,
je désire faire une simple requete par l'exmple qui me renvoit les occurences qui correspondent : (à noter que j'utilise Spring)



Code:
Balance b = new Balance();
      b.setBalanceDate(date);
      b.setAccount(anAccount);

getHibernateTemplate().execute(new HibernateCallback()
      {
            public Object doInHibernate(Session session) throws HibernateException
            {
                               Example ex = Example.create(b);
                return session.createCriteria(Balance.class).add(ex).uniqueResult();
            }
        });


Je crée donc une objet Balance avec deux attributs sur lesquels je veux me baser pour ma recherche.
Le problème est que hibernate ne semble faire la recherche que sur l'attribut date, l'objet account semble être ignoré

Je joins le mapping de Balance


Quote:
<hibernate-mapping
>
<class
name="com.planaxis.swifter.model.Balance"
table="BALANCE"
>

<id
name="idBalance"
column="ID_BALANCE"
type="java.lang.Long"
>
<generator class="increment">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Balance.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<many-to-one
name="account"
class="com.planaxis.swifter.model.Account"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="ID_ACCOUNT"
not-null="true"
/>

<property
name="balanceAmount"
type="java.lang.Float"
update="true"
insert="true"
column="BALANCE_AMOUNT"
/>

<property
name="balanceDate"
type="java.util.Date"
update="true"
insert="true"
column="BALANCE_DATE"
/>


</class>

</hibernate-mapping>


Hibernate version: 3


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 12:16 pm 
Newbie

Joined: Wed Aug 10, 2005 8:07 am
Posts: 14
Quote:
16.6. Example queries

Version properties, identifiers and associations are ignored. By default, null valued properties are excluded.


Donc en fait la solution est un truc comme ca :


Code:
               Example ex = Example.create(balance);
                return session.createCriteria(Balance.class)
                               .add(ex)
                               .add(Expression.like("account",balance.getAccount()))
                               .uniqueResult();


Ca semble passer !


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.