-->
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.  [ 3 posts ] 
Author Message
 Post subject: OneToMany Problems : "Bad" SQL being generated
PostPosted: Tue Jan 24, 2006 3:24 pm 
Beginner
Beginner

Joined: Tue Dec 21, 2004 11:53 am
Posts: 42
Hibernate version: 3.1
Database: Oracle 10g using ojdbc14 drivers
Hello there! I'm havin a little problem with Collections mapping using Annotations. Here's my persistent classes:

Code:

@Entity
@Table(name="VW_USUARIO")
@SuppressWarnings("serial")
public class Usuario{
@OneToMany(fetch=FetchType.EAGER,targetEntity=Produto.class)
   @OrderBy("ponto")
   public Set getProdutos() {
      return produtos;
   }
}

@Entity
@Table(name="VW_PRODUTO")
public class Produto{

}



This is an unidirectional relationship. Both tables (actually views) have composite keys

Usuario is composed by CODUSER, CONTRATO
Produto is composed by CIDADE,CONTRATO,PRODUTO

Ok, my problem is that the SQL generated by hibernate is trying to perform an outer join in a table called "VW_USUARIO_VW_PRODUTO" like there was a JoinTable in a manyToMany relationship.

What's wrong with this code?

Regards


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 4:07 pm 
Beginner
Beginner

Joined: Tue Dec 21, 2004 11:53 am
Posts: 42
Just adding: Just upgraded it to Hibernate 3.1.1 and Annotations Beta8

I've also tried to let it bi-directional:

Code:
@Entity
@Table(name="VW_USUARIO")
@SuppressWarnings("serial")
public class Usuario{
@OneToMany(fetch=FetchType.EAGER,targetEntity=Produto.class,mappedBy="usuario")
   public Set getProdutos() {
      return produtos;
   }
}

@Entity
@Table(name="VW_PRODUTO")
public class Produto{
@ManyToOne
private Usuario getUsuario(){
return usuario;
}
}


This time the error is that the SQL being generated contains an invalid column named: PRODUTOS2_"."USUARIO_ID.

It seems that Hibernate is not generating the correct mapping for those classes that have composite keys

Any ideas on this?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 25, 2006 2:53 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
default mapping for a unidirectional one to many is through an association table. This should be written in the doc (can you confirm, that's your punishment ;-) )
OrderBy is not supported with association table (an issue is open on that)

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.