-->
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.  [ 5 posts ] 
Author Message
 Post subject: Filtering records in xml
PostPosted: Fri Sep 09, 2005 3:54 pm 
Beginner
Beginner

Joined: Mon Jun 20, 2005 3:14 pm
Posts: 33
Hi,

I have this mapping and would like to get records with COD_SISTEMA=500.

I'm receiving this error: Attribute "formula" must be declared for element type "class"

How to do it?

Code:
<hibernate-mapping package="br.atech.atendeCOS.model" default-lazy="false">
  <class name="Sistema" table="TB_SISTEMA" schema="ADMCOS">
    <id name="codigo" type="short">
      <column name="COD_SISTEMA" precision="3" scale="0" formula="COD_SISTEMA=500" />
      <generator class="assigned" />
    </id>
  </class>
</hibernate-mapping>


Thanks,

Andre


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 12, 2005 3:43 am 
Beginner
Beginner

Joined: Mon Apr 12, 2004 6:33 pm
Posts: 35
First of all "COD_SISTEMA=500" is not a formula but an equation. Secondly you are not allowed to use formula in an id field.

Thirdly I think what you is to filter objects. In that case you should add "codigo = 500" to the where clause of your HQL query.

_________________
Kees de Kooter

(don't hesitate to rate ;)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 12, 2005 8:38 am 
Beginner
Beginner

Joined: Mon Jun 20, 2005 3:14 pm
Posts: 33
But can't I filter using xml file? have I to use HQL?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 12, 2005 8:44 am 
Beginner
Beginner

Joined: Mon Apr 12, 2004 6:33 pm
Posts: 35
In the xml file you define the mapping of domain objects to database tables. Filtering is something u usually do in code.

In this case you want to filter on the id field, so can also use something like session.load(Sistema.class, 500).

There is another way however: you can add

Code:
where="arbitrary sql where condition"
to your class mapping.

hth

_________________
Kees de Kooter

(don't hesitate to rate ;)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 12, 2005 12:44 pm 
Beginner
Beginner

Joined: Mon Jun 20, 2005 3:14 pm
Posts: 33
Thanks Kees!


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