-->
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: Problems joining two tables
PostPosted: Thu Jan 22, 2009 6:10 pm 
Newbie

Joined: Wed Jan 21, 2009 9:36 am
Posts: 5
Hi, I have a problem. I need a question like this:

select *
from vsc_userversion AS a inner join vsc_usuario as b
on a.idusuario=b.id_ where b.id_=a.idusuario and b.nombre="carlo"

however i get something like this:

select *
from vsc_userversion AS a inner join vsc_usuario as b
on a.id_=b.id_ where b.id_=a.idusuario and b.nombre="carlo"

The difference is that I want on a.idusuario=b.id_ and hibernate make on a.id_=b.id_

Somebody know how fix this?. Thanks for your answers and sorry for my inglish. My inglish sucks :(



Mapping documents:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="cl.vsoft.liferay.domain.Userversion" table="vsc_userversion">
<id name="id" column="id_">
<generator class="native" />
</id>
<property name="idusuario" column="idusuario" />
<property name="idinstancia" column="idinstancia" />
<property name="idversion" column="idversion" />
<property name="idproceso" column="idproceso" />


<one-to-one name="Usuario"
class="cl.vsoft.liferay.domain.UsuarioPostulacion"
fetch="join"
foreign-key = "idusuario"
/>

</class>
</hibernate-mapping>

Name and version of the database you are using:
mysql

The generated SQL (show_sql=true):

18:55:55,225 INFO [STDOUT] Hibernate: select this_.id_ as id1_9_1_, this_.idusuario as idusuario9_1_, this_.idinstancia as idinstan3_9_1_, this_.idversion as idversion9_1_, this_.idproceso as idproceso9_1_, a1_.id_ as id1_8_0_, a1_.username as username8_0_, a1_.nombre as nombre8_0_, a1_.apellidopaterno as apellido4_8_0_ from vsc_userversion this_ inner join vsc_usuario a1_ on this_.id_=a1_.id_ where a1_.id_=this_.idusuario and a1_.nombre=?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2009 6:21 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
The problem is the <one-to-one> mapping. It is only used when the mapping is on the primary key. When it is on a different column you should use <many-to-one ... column="..." unique="true" />. Eg. something like:

Code:
<many-to-one
  name="Usuario"
  column="idusuario"
  unique="true"
  class="cl.vsoft.liferay.domain.UsuarioPostulacion"
  fetch="join"
  foreign-key = "idusuario"
/>


Read more here: http://www.hibernate.org/hib_docs/v3/re ... n-onetoone


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.