java - EclipseLink doesn't include generate options on a ManyToMany relationship -


i'm having issues eclipselink / jpa (2.5.2), postgresql (9.3) , schema generation. spring application, love create @manytomany relationship between 2 classes, refuses create third middle table supplied 2 cascade options.

both classes have proper implementations of hashcode() , equals(...) , both involved in other relationships, non @manytomany of course, support cascade options , work fine.

[stream]-(0..n)--<streams_tags>--(0..n)-[tag] 

the following fragment of ddl script regarding manytomany relationship:

create table streams_tags (tagged_streams integer not null, tags integer not null, primary key (tagged_streams, tags)) ... alter table streams_tags add constraint unq_streams_tags_0 unique (tags, tagged_streams) ... alter table streams_tags add constraint fk_streams_tags_tagged_streams foreign key (tagged_streams) references tags (tid) ... alter table streams_tags add constraint fk_streams_tags_tags foreign key (tags) references streams (sid) 

the following stubs extracted straight involved classes, stream , tag:

@manytomany(cascade = cascadetype.all) @jointable(name = stream.tags_join_table,              joincolumns = @joincolumn(name = stream.tags_join_column),              inversejoincolumns = @joincolumn(name = tag.tagged_streams_join_column),              uniqueconstraints = @uniqueconstraint(columnnames = {         stream.tags_join_column, tag.tagged_streams_join_column })) @cascadeondelete list<tag> tags; 

the following tag class, doesn't hold directly relationship.

@manytomany(mappedby = "tags")   list<stream> streams; 

and predictable error received when try delete tagged stream:

error: update or delete on table "streams" violates foreign key constraint "fk_streams_tags_tags" on table "streams_tags"   dettaglio: key (sid)=(2) still referenced table "streams_tags". 

thank in advance, appreciated! :)

you using @cascadeondelete tells eclipselink database handle deleting streams_tags references, described here: http://www.eclipse.org/eclipselink/documentation/2.4/jpa/extensions/a_cascadeondelete.htm

either remove annotation eclipselink remove join table, or change ddl on delete cascade included or let eclipselink generate ddl http://wiki.eclipse.org/eclipselink/examples/jpa/ddl or through jpa using http://wiki.eclipse.org/eclipselink/release/2.5/jpa21#ddl_generation


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -