Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to clean database due to Foreign Key Constraint Violation #20

Open
paulovictorv opened this issue Nov 9, 2012 · 10 comments
Open

Comments

@paulovictorv
Copy link

Hi, I'm having a problem with I suppose is with this extension, not the underlying DBUnit infrastructure. When the extension tries to clean the database after a test method, it fails to clean the database due to a foreign key constraint violation. The test method is as follows:

@test
@ShouldMatchDataSet("datasets/users-company.xml")
public void saveClientWithCompany(){
Client s = new Client();
s.setLogin("solicitante1");
s.setEmail("[email protected]");
s.setNome("paulo");
s.setSenha("123456");
s.setDepartamento("dep");
Company e = new Company();
e.setNome("empresa");
Set set = new HashSet();
set.add(s);
e.setListClient(set);
s.setCompany(e);
solMgt.saveClient(s);
}

As you can see, there is a ManyToOne relation between Client and Company, and there is a constraint in this relationship.
I tried to use @ApplyScriptBefore to deactivate the constraint check, but with no success. Apparently, the extension does not run the script, since if I run the command by hand it works as it should.

@bartoszmajsak
Copy link
Member

Would it be possible to attach test case and used files in the forum community.jboss.org in arquillian space? thx!

@bartoszmajsak
Copy link
Member

or ideally extracted project with failing test :)

@paulovictorv
Copy link
Author

Of course. I will open a new thread there :)

@bartoszmajsak
Copy link
Member

thank you, I will take care of the rest

@paulovictorv
Copy link
Author

@paulovictorv
Copy link
Author

Hi, did you get a chance to see the topic? Is there something missing? Thanks

@bartoszmajsak
Copy link
Member

Sorry, not yet. At Devoxx at the moment, but hopefully I will have time for that today :)

@bartoszmajsak
Copy link
Member

The test itself is not that helpful. Could you provide entities as well? Also which version of Arquillian and Persistence Extension are you using? Which MySQL version and AS?

@bartoszmajsak
Copy link
Member

Are you still facing the problem? Otherwise I would like to close this issue

@shoteff
Copy link

shoteff commented Apr 8, 2016

Hi,
I also faced the foreign key violation on DB cleanup. I'm using JSON datasets, MySQL DB with referential integrity enabled. The inserts into the DB are ordered as the definitions in the dataset(s). In order to avoid foreign key violations I have to first define the parent side of the relations (I'm assuming that there are no circular deps), then the childs. Cleaning up the data should be done in reverse order (not like it is currently in the order the data is inserted). At least from my point of view this can solve the problem in the most cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants