-->
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: JPA OneToMany require a mid-table?
PostPosted: Sat Sep 30, 2006 9:02 pm 
Newbie

Joined: Fri Feb 17, 2006 12:18 am
Posts: 11
Hi, i'm using Hibernate 3.2 rc2 and hibernate annotation.

When i'm using a OneToMany relationship with class A, B, i found it is strange that hibernate-tools generate tables: A, B and A_B!

however, i don't think table A_B is neccessary when using OneToMany. so i only create table A and B, and this causes runtime exception:

Hibernate operation: could not initialize a collection: bad SQL grammar[select ...]
nested exception is java.sql.SQLException: Table 'A_B' doesn't exist

is there anyting wrong with my annontation?

@OneToMany(targetEntity=B.class)
public List getBs() { return list; }
public void setBs(List list) { this.list=list; }

thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 02, 2006 5:17 am 
Newbie

Joined: Fri Feb 17, 2006 12:18 am
Posts: 11
i found the point: must specify a mappedBy and point to property of B's getA() method:

@OneToMany(targetEntity=B.class, mappedBy="a")
public List getBs() { return list; }
public void setBs(List list) { this.list=list; }


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.