-->
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.  [ 1 post ] 
Author Message
 Post subject: Simple INNER JOIN with pure criteria.. how to?
PostPosted: Mon Sep 12, 2011 10:18 am 
Newbie

Joined: Thu Sep 23, 2010 11:14 am
Posts: 10
Hi All!!

My problem is that I want to do a simple inner join only with criteria or with minimun mapping elements.
More data:

I Have 2 entities: movimiento and categoria
Code:
mysql> describe movimiento;
+-----------------+--------------+------+-----+---------+----------------+
| Field           | Type         | Null | Key | Default | Extra          |
+-----------------+--------------+------+-----+---------+----------------+
| mo_id           | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| mo_cl_id        | bigint(20)   | YES  |     | NULL    |                |
| mo_em_id        | bigint(20)   | YES  |     | NULL    |                |
| mo_tipo         | varchar(255) | NO   |     | NULL    |                |
| mo_categoria_id | bigint(20)   | NO   |     | NULL    |                | <--- categoria ID
| mo_importe      | float        | YES  |     | NULL    |                |
| mo_fecha        | bigint(20)   | NO   |     | NULL    |                |
| mo_detalle      | varchar(500) | YES  |     | NULL    |                |
+-----------------+--------------+------+-----+---------+----------------+

mysql> describe categoria;
+-----------------+--------------+------+-----+---------+----------------+
| Field           | Type         | Null | Key | Default | Extra          |
+-----------------+--------------+------+-----+---------+----------------+
| cat_id          | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| cat_nombre      | varchar(255) | NO   |     | NULL    |                |
| cat_descripcion | varchar(255) | YES  |     | NULL    |                |
| cat_has_persona | varchar(255) | YES  |     | NULL    |                |
| cat_mov_tipo    | varchar(255) | YES  |     | NULL    |                |
+-----------------+--------------+------+-----+---------+----------------+


I want to get a list of movimiento when mo_categoria_id (ID of categoria) is a categoria with (categoria.)cat_mov_tipo = 'Egreso'.
The simple query is this:
Code:
SELECT * FROM movimiento mov INNER JOIN categoria cat ON mov.mo_categoria_id=cat.id WHERE cat_mov_tipo = 'Egreso';


With criteria, I made a criteria of movimiento entities and I want to make a inner join with categoria to restrict cat_mov_tipo to 'Egreso'.

I don't know if this is a many-to-many, or one-to-many or who.
I don't put here my mapping configuration because I don't want to make a list with many-* on mapping files. So, if the only way is with mapping please tell me and I will put these xml.

Thanks in advance
Sorry About my english
Regards Juan Pablo


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

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.