-->
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: Table with that name already associate
PostPosted: Mon Apr 11, 2016 1:16 pm 
Newbie

Joined: Mon Apr 11, 2016 1:04 pm
Posts: 1
I have the following classes User, Region, Country as follows,

public class User {

@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
@Column(name = "first_name")
Private String firstName;
@Column(name = "last_name")
private String lastName;
@OneToOne(fetch = FetchType.EAGER)
@JoinTable(name = "user_country_region", joinColumns ={@JoinColumn(name = "user_id") }, inverseJoinColumns = { @JoinColumn(name = "country_id") })
private Country userCountry;

@OneToOne(fetch = FetchType.EAGER)
@JoinTable(name = "user_country_region", joinColumns = {@JoinColumn(name = "user_id") }, inverseJoinColumns = { @JoinColumn(name = "region_id") })
private Region userRegion;

//With its respective Getters and Setters
}

public class Country {

@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
@Column(name = "name")
private String name;

//With its respective Getters and Setters
}

public class Region {

@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
@Column(name = "name")
private String name;

//With its respective Getters and Setters
}

Tried getting country and region values as below

System.out.println("Country: "+user.getCountry().getName());
System.out.println("Region: "+user.getRegion().getName());

Hibernate Show SQL output as below

Hibernate:
select
this_.id as id1_3_3_,
this_.first_name as first_na2_3_3_,
this_.last_name as last_na3_3_3_,
region2_.id as id1_8_2_,
region2_.name as name2_8_2_
from
user this_
left outer join
user_country_region this_1_
on this_.id=this_1_.user_id
left outer join
region region2_
on this_1_.region_id=region2_.id
where
this_.id=?

Seems missing country details. Kindly assist.


Top
 Profile  
 
 Post subject: Re: Table with that name already associate
PostPosted: Tue Apr 12, 2016 1:23 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
It could be a bug because Hibernate considers that it already joined with "user_country_region" table.

In this case, you either define two junction tables:

- user_country
- user_region

or create a replicating test case and file a Jira issue.


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.