History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: UNI-174
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Stephan Kleine
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Unitils

Disabling constraints doesn't work

Created: 05/Nov/09 03:08 PM   Updated: 09/Nov/09 08:05 PM
Component/s: None
Affects Version/s: 3.0
Fix Version/s: 3.0

File Attachments: 1. File unitils-testcase-tar.bz2 (3 kb)



 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.

 All   Comments   Change History      Sort Order:
Stephan Kleine - 05/Nov/09 03:09 PM
Small test case showing the problem

Filip Neven - 07/Nov/09 08: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.

Stephan Kleine - 09/Nov/09 08: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.