openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henno Vermeulen <he...@huizemolenaar.nl>
Subject RE: no primary key on generated join table
Date Thu, 20 Sep 2012 14:47:37 GMT
To only partially answer my own question, I can have OpenJPA generate a unique constraint when
I add something like:

	@ManyToMany
	@JoinTable(joinColumns = { @JoinColumn(name = "CONTACT_ID") }, 
	inverseJoinColumns = { @JoinColumn(name = "MAILINGLISTS_ID") }, 
	uniqueConstraints = { @UniqueConstraint(columnNames = {
			"CONTACT_ID", "MAILINGLISTS_ID" }) })
	private List<MailingList> mailingLists = new ArrayList<MailingList>();

Here I used the default column names that OpenJPA generates for me.
However this is not a primary key. Plus I think it's rather ugly having to add boiler plate
like this; isn't JPA intended to minimize having to write boilerplate code?


-----Oorspronkelijk bericht-----
Van: Henno Vermeulen [mailto:henno@huizemolenaar.nl] 
Verzonden: donderdag 20 september 2012 16:37
Aan: 'users@openjpa.apache.org'
Onderwerp: no primary key on generated join table

When I use @ManyToMany on a List or Set and let OpenJPA generate my database schema, it creates
a join table with two foreign key columns that allows duplicates.

Is there a way to let OpenJPA generate a compound primary key on both the foreign key columns
or should I manually add these in the database?
Or is not a problem when a join table has no primary key?


Mime
View raw message