-->
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: why is hibernate ignoring JoinTable annotation?
PostPosted: Mon Apr 24, 2017 6:44 pm 
Newbie

Joined: Mon Dec 12, 2016 3:45 pm
Posts: 16
I am trying to get JoinTable annotation to work using hibernate. My entities look like:

Code:
@Entity
@Table("users")
public class User {
    @Id
    @GeneratedValue
    private int id;
    @ManyToOne
    @JoinTable(name = "joinTable",
            joinColumns = @JoinColumn(name = "userId", referencedColumnName = "id"),
            inverseJoinColumns = @JoinColumn(name = "roleId", referencedColumnName = "id")
    )
    private Role role;
}


Code:
@Entity
@Table("roles")
public class Role {
    @Id
    @GeneratedValue
    private int id;
}


If I issue a query like:
Code:
select u from User u where u.role.id = :roleid


The generated query is:
Code:
select
        user0_.id as id1_0_,
        user0_.roleid as role1_2_
    from
        users user0_
    where
        user0_.roleid=?


This query was previously working when user and role had different property names for their "id" (userId and roleId respectively)


Top
 Profile  
 
 Post subject: Re: why is hibernate ignoring JoinTable annotation?
PostPosted: Tue Apr 25, 2017 1:25 pm 
Newbie

Joined: Mon Dec 12, 2016 3:45 pm
Posts: 16
okay, this turned out to be caused by an invalid inheritance mapping. My BaseModel class wasn't annotated with @MappedSuperClass


Top
 Profile  
 
 Post subject: Re: why is hibernate ignoring JoinTable annotation?
PostPosted: Thu Apr 27, 2017 10:27 am 
Newbie

Joined: Thu Apr 27, 2017 10:22 am
Posts: 1
invalid inheritance mapping? makes sense. thanks for sharing the solution

Flirt with cam girls the right way


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.