-->
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.  [ 1 post ] 
Author Message
 Post subject: JPA's @ForeignKey not working for @ManyToMany
PostPosted: Wed Sep 10, 2014 4:21 am 
Beginner
Beginner

Joined: Mon Sep 27, 2004 11:51 pm
Posts: 22
Hi,

l am using

'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.0.Final'
'org.hibernate', name: 'hibernate-entitymanager', version: '4.3.6.Final'

The code below work ,
Code:
    @ManyToMany
    @JoinTable(name="biblio_author",
              joinColumns=@JoinColumn(name="biblio_id"),
              inverseJoinColumns=@JoinColumn(name="author_id")) 
    @org.hibernate.annotations.ForeignKey(name="fk_biblioauthor_biblio" , inverseName="fk_biblioauthor_author")
    private Set<Author> authors = new HashSet<Author>(0);

It generated :
Code:
Hibernate: alter table biblio_author add constraint fk_biblioauthor_author foreign key (author_id) references author (id)
Hibernate: alter table biblio_author add constraint fk_biblioauthor_biblio foreign key (biblio_id) references biblio (id)

The code below don't work ,
Code:
    @ManyToMany
    @JoinTable(name="biblio_author",
              joinColumns=@JoinColumn(name="biblio_id", foreignKey = @ForeignKey(name = "fk_biblioauthor_biblio")),
              inverseJoinColumns=@JoinColumn(name="author_id" , foreignKey = @ForeignKey(name = "fk_biblioauthor_author"))) 
    private Set<Author> authors = new HashSet<Author>(0);

It generated :
Code:
Hibernate: alter table biblio_author add constraint FK_exs5c651sjsh6gns6dxmos7dq foreign key (author_id) references author (id)
Hibernate: alter table biblio_author add constraint FK_1reuuv3csiedk2uotsklldkba foreign key (biblio_id) references biblio (id)


Thanks

Moon


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.