Unitils

Disabling constraints doesn't work

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 3.0
  • Fix Version/s: 3.0
  • Component/s: None
  • Description:
    Hide
    For some reason Unitils doesn't disable my constraints.

    A small test case that shows the problem is attached. Notice how there is absolutely no hint in the log about disabling constrains although dbMaintainer.disableConstraints.enabled=true is in my unitils.properties.

    If you use a custom DisableConstraintModule by simply uncommenting lines 15 - 18 in unitils.properties you can see in the log that constraints get actually disabled now (e.g. "INFO: Disabling constraints in database schema PUBLIC") but still the test fails cause they aren't actually disabled.

    So, basically there are 2 problems:

    1. Setting dbMaintainer.disableConstraints.enabled=true doesn't disable the constraints in the first place although it should suffice if I got your docs right.

    2. Even when "manually" disabling them (by using a custom DisableConstraintModule) they don't get disabled for the used datasource.
    Show
    For some reason Unitils doesn't disable my constraints. A small test case that shows the problem is attached. Notice how there is absolutely no hint in the log about disabling constrains although dbMaintainer.disableConstraints.enabled=true is in my unitils.properties. If you use a custom DisableConstraintModule by simply uncommenting lines 15 - 18 in unitils.properties you can see in the log that constraints get actually disabled now (e.g. "INFO: Disabling constraints in database schema PUBLIC") but still the test fails cause they aren't actually disabled. So, basically there are 2 problems: 1. Setting dbMaintainer.disableConstraints.enabled=true doesn't disable the constraints in the first place although it should suffice if I got your docs right. 2. Even when "manually" disabling them (by using a custom DisableConstraintModule) they don't get disabled for the used datasource.
  1. unitils-testcase-tar.bz2
    (3 kB)
    Stephan Kleine
    05/Nov/09 3:09 PM

Activity

Hide
Stephan Kleine added a comment - 05/Nov/09 3:09 PM
Small test case showing the problem
Show
Stephan Kleine added a comment - 05/Nov/09 3:09 PM Small test case showing the problem
Hide
Filip Neven added a comment - 07/Nov/09 8:47 PM
The property dbMaintainer.disableConstraints.enabled=true only works when you use unitils to update your database, using the dbmaintainer. It appears that your schema is generated using hibernate. Simply call DatabaseUnitils.disableConstraints() instead.

The reason that we don't perform disabling if the dbmaintainer is not used, is that in that case we don't know whether the database schema was updated. For most projects running the disable constraints operation is costly, even when there's nothing to disable anymore. You don't want to wait for this operation to complete before each test run. Therefore we let the user decide when it's needed to run this operation again.
Show
Filip Neven added a comment - 07/Nov/09 8:47 PM The property dbMaintainer.disableConstraints.enabled=true only works when you use unitils to update your database, using the dbmaintainer. It appears that your schema is generated using hibernate. Simply call DatabaseUnitils.disableConstraints() instead. The reason that we don't perform disabling if the dbmaintainer is not used, is that in that case we don't know whether the database schema was updated. For most projects running the disable constraints operation is costly, even when there's nothing to disable anymore. You don't want to wait for this operation to complete before each test run. Therefore we let the user decide when it's needed to run this operation again.
Hide
Stephan Kleine added a comment - 09/Nov/09 8:05 PM
> The property dbMaintainer.disableConstraints.enabled=true only works when you use unitils to update your database, using the dbmaintainer.

You are right, I currently use jpa to maintain my database and it works when I switch to dbmaintainer (explicitly stating that in the docs would be great to avoid confusion ;))

However, calling "DatabaseUnitils.disableConstraints()" either in the test method or in some other one annotated with @BeforeSuite / BeforeWhatever doesn't help. I get "INFO: Disabling constraints in database schema PUBLIC" shown in the log but inserting my test data still fails because of the constraints not being disabled.

How to reproduce with the above test case:

Insert the following method into the BookDAOLocalBeanTest class:
    
    @BeforeSuite
    public void disableConstraints() {
        logger.info("Disabling constraints");
        DatabaseUnitils.disableConstraints();
        logger.info("Contraints disabled");
    }

Therefore please reopen this bug because the issue still exists and the suggested workaround doesn't work.
Show
Stephan Kleine added a comment - 09/Nov/09 8:05 PM > The property dbMaintainer.disableConstraints.enabled=true only works when you use unitils to update your database, using the dbmaintainer. You are right, I currently use jpa to maintain my database and it works when I switch to dbmaintainer (explicitly stating that in the docs would be great to avoid confusion ;)) However, calling "DatabaseUnitils.disableConstraints()" either in the test method or in some other one annotated with @BeforeSuite / BeforeWhatever doesn't help. I get "INFO: Disabling constraints in database schema PUBLIC" shown in the log but inserting my test data still fails because of the constraints not being disabled. How to reproduce with the above test case: Insert the following method into the BookDAOLocalBeanTest class:          @BeforeSuite     public void disableConstraints() {         logger.info("Disabling constraints");         DatabaseUnitils.disableConstraints();         logger.info("Contraints disabled");     } Therefore please reopen this bug because the issue still exists and the suggested workaround doesn't work.

People

Dates

  • Created:
    05/Nov/09 3:08 PM
    Updated:
    09/Nov/09 8:05 PM
    Resolved:
    07/Nov/09 8:47 PM