-->
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: Criteria + join of join
PostPosted: Thu May 05, 2005 4:04 am 
Regular
Regular

Joined: Wed Sep 22, 2004 8:27 am
Posts: 89
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0

Mapping documents:

1- Categoria

<hibernate-mapping default-lazy="false">
<class name="com.coginfo.kf.bean.Categoria" table="KFT_CATEGORIA" select-before-update="true">
<id name="codint" type="long" unsaved-value="0">
<generator class="sequence">
<param name="sequence">KF_SEQ_CATEGORIA</param>
</generator>
</id>

<property name="cafdsc" type="string">
<column name="cafdsc" length="1000" sql-type="string" not-null="true"/>
</property>


<set name="categoriaAclAmministratori" where="stsacl = '1'">
<key column="codintctg"/>
<one-to-many class="com.coginfo.kf.bean.CategoriaAcl"/>
</set>
</class>
</hibernate-mapping>

-KFT_CATEGORIA_ACL

<hibernate-mapping default-lazy="false">
<class name="com.coginfo.kf.bean.CategoriaAcl" table="KFT_ACL_CATEGORIA" select-before-update="true">
<composite-id name="id" class="com.coginfo.kf.bean.CategoriaAclPk">
<key-many-to-one name="codintacl" class="com.coginfo.kf.bean.Acl"/>
<key-many-to-one name="codintctg" class="com.coginfo.kf.bean.Categoria"/>
<key-property name="stsacl"/>
</composite-id>

<discriminator column="stsacl" insert="false"/>

<subclass name="com.coginfo.kf.bean.CategoriaAclAdm" discriminator-value="1"/>
<subclass name="com.coginfo.kf.bean.CategoriaAclSvil" discriminator-value="2"/>
<subclass name="com.coginfo.kf.bean.CategoriaAclCol" discriminator-value="3"/>
</class>
</hibernate-mapping>

- ACL

is a simple map with id and property cafute


I must write with Criteria this sql:
select ca.* from kft_categoria c, kft_acl_categoria ca, kft_acl acl
where ca.codintctg = c.codint and ca.codintacl = acl.codint and acl.cafute = 'AV09901' and ca.stsacl = '1'


Can anyone help me plz?

thanks


Top
 Profile  
 
 Post subject: solution?
PostPosted: Mon May 09, 2005 11:01 am 
Regular
Regular

Joined: Wed Sep 22, 2004 8:27 am
Posts: 89
any help? any solutions?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 09, 2005 2:00 pm 
Regular
Regular

Joined: Mon Jul 26, 2004 2:28 pm
Posts: 86
Location: Pensacola, Florida
You didn't really provide a whole lot of information, but here's a stab:

Code:
session.createCriteria( CategoriaAclAdm.class )
   .createCriteria( Acl.class )
      .add( Expression.eq( "cafute", "AV09901" ) )
   .list( );


I don't really know how discriminators fit into Criteria queries; I suspect you would just reference the subclass in the initial createCriteria( ) call (I could be wrong). If I am, then you can probably do something like this:

Code:
session.createCriteria( CategoriaAclAdm.class )
   .add( Expression.eq( "stsacl", "1" ) )
   .createCriteria( Acl.class )
      .add( Expression.eq( "cafute", "AV09901" ) )
   .list( );


Not sure, though. I suspect this is covered in the criteria query section of the documentation.

- Jesse


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 10, 2005 3:33 am 
Regular
Regular

Joined: Wed Sep 22, 2004 8:27 am
Posts: 89
thanks, but i 've just wrote this code but it is not what i want, becouse, i would get all categories like this query :

select ca.* from kft_categoria c, kft_acl_categoria ca, kft_acl acl
where ca.codintctg = c.codint and ca.codintacl = acl.codint and acl.cafute = 'AV09901' and ca.stsacl = '1'


your solution find only records about this table: kft_acl_categoria.

I need a criteria that connect in join 3 tables. kft_categoria , kft_acl_categoria , kft_acl

thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 10, 2005 9:39 am 
Regular
Regular

Joined: Mon Jul 26, 2004 2:28 pm
Posts: 86
Location: Pensacola, Florida
The query

Code:
select ca.* ...


Will only select columns from the "ca" alias (the kft_acl_categoria table), so I thought that was the desired result. I think you can use HQL to return maps of objects or you can use subselect fetching (which I know nothing about).

- Jesse


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.