Mod4j: Modeling for Java using Domain Specific Languages

Configuration error in the generated hbm.xml

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0.1
  • Fix Version/s: 1.1.0
  • Labels:
    None
  • Number of attachments :
    0

Description

Problem

Given a not-null foreign key constraint in the database and a bi-directory one-to-many association. Mod4j now generates a configuration that causes it to be impossible to delete children (the many side of the association) .

Cause

See (17.2):
https://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/example-parentchild.html
And:
https://www.hibernate.org/209.html

In the Basic Collection pattern the mapping works like this:
1. The parent maps the set containing the children to the appropriate
child table as a one-to-many relationship, e.g. one parent to many
children.

2. The parent marks the relationship as "inverse". This attribute says
that the parent doesn't actually update the relationship; the child
updates the relationship. We do this so that we can deal with "NOT
NULL" constraints on the child side.

DEFECT: the inverse property in the Parent.hbm.xml is FALSE and it should be TRUE.

I think due to the fact in the test application RecordShop Hibernate generates the DDL this problem does not come to light. It does, however, when using a hand-written datamodel that is set up to keep the one2many association consistent. In the RecordShop the foreign key column is NULL and in my datamodel it is NOT NULL.

Solution

Update the XPand template to generate inverse=true in case of a bidirectorional one-to-many association.

This was tested by manually changing the generated hbm.xml and running a integration test that does a cascading delete of a one-to-many association.

New best-practice for Hibernate and thus for mod4j

Don't use unidirectional one-to-many associations, make them bidrectional instead.

Issue Links

Activity

Hide
Vincent Lussenburg added a comment -

Please update the component (I cannot), it should be Domain DSL instead of Data Contract DSL.

Show
Vincent Lussenburg added a comment - Please update the component (I cannot), it should be Domain DSL instead of Data Contract DSL.
Hide
Johan Vogelzang added a comment -

Added inverse="true" for bi-directional one-to-many and ordered-one-to-many mappings

Show
Johan Vogelzang added a comment - Added inverse="true" for bi-directional one-to-many and ordered-one-to-many mappings

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: