Generating on delete restrict on update restrict for H2 join table

122 views
Skip to first unread message

Tim Almdal

unread,
May 4, 2017, 1:28:19 PM5/4/17
to Ebean ORM
I have the following tables:

@Entity
class TableA {
  @Id
  private String id

  @ManyToMany(fetch = LAZY)
  @JoinTable(name = "tablea_tableb")
  private Set<TableB> tablebList;
}

@Entity
class TableB {
  @Id
  private String id
}

When I run my unit tests I get the join table generated properly, but it also generated referential constrains from the join table (tablea_tableb) to the source tables (tableA and tableB) with on delete restrict and on update restrict.

In our deployment the join table is created without the on delete and on update clauses.  The application expects to be able to delete the source tables.

I've tried adding cascade=CascadeType.All or CascadeType.REMOVE but it always generates the on delete restrict and on update restrict clauses.

I'm currently trying use V3.1.2.

Is there away to disable this generation? Or, was this a problem with this version, but was fixed in a later released?

Thanks
Tim

Rob Bygrave

unread,
May 7, 2017, 7:32:58 AM5/7/17
to ebean@googlegroups
> it always generates the on delete restrict and on update restrict clauses.

As we generally don't want invalid foreign key values.
 

>
Is there away to disable this generation?

Not at this stage no (except via manually manipulating "DB Migrations").


> Or,
 was this a problem with this version, but was fixed in a later released?

Well, it is not considered a problem per say in that we don't want to allow invalid foreign key values.  We have https://github.com/ebean-orm/ebean/issues/323 ... logged which when resolved would provide foreign keys with cascade delete (and in doing so limits the L2 caching options on the children etc).

... but I believe the DDL you are wanting allows invalid foreign keys?  Is that the goal?






--

---
You received this message because you are subscribed to the Google Groups "Ebean ORM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tim Almdal

unread,
May 8, 2017, 10:00:29 AM5/8/17
to Ebean ORM
Thanks for the reply.

What is happening is in our application, we try to delete all the TableB's from the data
base we get a "Referential integrity constraint violation" on the join table trying to reference TableB.  This only happens with h2 in the unit tests.  When deployed, we have defined the referential table without delete or update restricts.

What is the correct ebean way to delete one side of a many-to-many?

Is it the deleteManyToManyAssociation? I know that goes away in 7.4.1.   Is there a better way so I don't have to rewrite it again when I try upgrading past 7.4.1. (Remembering I am currently on 3.1.1 trying to migrate to 3.2.1.

Thanks for any insights or help.
Tim

To unsubscribe from this group and stop receiving emails from it, send an email to ebean+un...@googlegroups.com.

Tim Almdal

unread,
May 9, 2017, 10:52:23 AM5/9/17
to Ebean ORM
NM, I think the problem is that there is leakage between tests (not cleaning up completely) and the error message is a result of that leakage
Reply all
Reply to author
Forward
0 new messages