-->
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 - Unidirectional - without Join Table - problem
PostPosted: Thu Mar 17, 2011 5:38 am 
Newbie

Joined: Thu Mar 17, 2011 5:31 am
Posts: 7
Hi,

am using hibernate 3.5.4

I have defined a Class like this:

ClassA.java
------------------------
Code:
   @Entity
   @Table(name="TABLE1")
   Class ClassA{
   
      .
      .
      .
      
      @Column(name="REF_B")
      private String a_obj;

      @OneToMany(fetch=FetchType.EAGER)
      @JoinTable(joinColumns = {
         @JoinColumn(name = "REF_A", referencedColumnName = "REF_B", unique = false, nullable = true)
      })
      private List<BClass> a_Objects;
      ..
      //getters and setters

   }

AND

ClassB.java
-------------------------
Code:
@Entity
   @Table(name="TABLE2")
   Class ClassB{
   
      .
      .
      .
      @Column(name="REF_A")      
      private String b_object;
      ..
      //getters and setters

   }
---------------------------




The Basic Idea is this...

1. I have a Table 'TABLE1'; which has a column 'TABLE1.REF_B' (Non-Unique/Nullable).
2. This column may contain a String value.
3. This String value will be present in some or the other row in 'TABLE2' matching with 'TABLE2.REF_A ' column (Non-unique/nullable).
4. It is possible and valid that there might be many rows in TABLE2 havings same value for REF_A.
5. All the rows from TABLE2 which match TABLE1.REF_B value must be populated in the 'List<BClass> a_objects'.

The mapping which i have defined above is not working, it gives me an error like..

Invalid object name 'TABLE1_TABLE2'

Is there something i am missing in the mapping? It is supposed to be Unidirectional and without a join table.

Note: REF_A and REF_B are not primary or foreign keys.


Top
 Profile  
 
 Post subject: Re: OneToMany - Unidirectional - without Join Table - problem
PostPosted: Thu Mar 17, 2011 6:14 am 
Regular
Regular

Joined: Fri Jan 28, 2011 11:44 am
Posts: 117
Here is how you define a OneToMany with a JoinTable :

Code:
@OneToMany(fetch=FetchType.EAGER)
@JoinTable(joinColumns=@JoinColumn(name="REF_B"), inverseJoinColumns=@JoinColumn(name="REF_A"))
private List<BClass> a_Objects;


Top
 Profile  
 
 Post subject: Re: OneToMany - Unidirectional - without Join Table - problem
PostPosted: Thu Dec 15, 2011 1:43 pm 
Regular
Regular

Joined: Tue Feb 19, 2008 6:05 pm
Posts: 82
the user specifically said without a third join table? Isn't there a way without the join table and with multiple keys?


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.