openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henno Vermeulen <>
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:

	@JoinTable(joinColumns = { @JoinColumn(name = "CONTACT_ID") }, 
	inverseJoinColumns = { @JoinColumn(name = "MAILINGLISTS_ID") }, 
	uniqueConstraints = { @UniqueConstraint(columnNames = {
	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 [] 
Verzonden: donderdag 20 september 2012 16:37
Aan: ''
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?

View raw message