Adding CMR is handled differently in JBoss 3.2.2 and JBoss 3.2.5
----------------------------------------------------------------
Key: JBAS-72
URL:
http://jira.jboss.com/jira/browse/JBAS-72
Project: JBoss Application Server
Issue Type: Bug
Security Level: Public(Everyone can see)
Components: CMP service
Affects Versions: JBossAS-3.2.5 Final
Environment: Windows XP
Oracle 9i
Reporter: Jbm Jbm
Assigned To: Alexey Loubyansky
Fix For: JBossAS-4.0.4.GA
Attachments: TestCMR.zip
When adding a CMR entity via DTO generated by XDoclet, it seems that the
"commit" append in different way in version 3.2.2 and 3.2.5, generating SQL
exceptions when using for example UNIQUE constraint refering to a foreign key in JBoss
3.2.5 (Test is working in 3.2.2)
============================================================================================
EXAMPLE
============================================================================================
This use case is the closest I could make to reproduce the error we have in our
application.
I have 3 entities :
- CompanyGroup
- Company
- Employee
With relationships :
- CompanyGroup - Company (1-n)
- Company - Employee (1-n)
An employee as a type ("boss" or "worker").
A company can have only one boss therefore the employee table has a unique constraint on
(companyID, type).
NOTE : This is not very logical or practical in normal life (since it also means that
there is only one worker), but it is just to introduce and illustrate the UNIQUE
constraint which will crash the application in 3.2.5.
In our DB we already have a CompanyGroup which contains 2 companies.
We want to add one new employee per companies of that group.
NOTE : The CMP and DTO code is generated by XDoclet
In our main class we will then call :
// Create a new boss for each company of the group
// CompGroup ID = 10
CompGroup mycg = cgHome.findByPrimaryKey(new Long(10));
CompGroupDTO mycgDTO = mycg.getCompGroupDTO();
CompanyDTO[] comps = mycgDTO.getCompanyDTOs();
int cLength = comps.length;
for (int i = 0; i < cLength; i++) {
EmployeeDTO eDTO = new EmployeeDTO();
eDTO.setEmployeeType("boss");
eDTO.setEmployeeName("John Doe " + i);
eDTO.setEmployeeId(new Long("3" + String.valueOf(i)));
comps[i].addEmployeeDTO(eDTO);
mycgDTO.updateCompanyDTO(comps[i]);
}
mycg.setCompGroupDTO(mycgDTO);
In 3.2.2 the test is successful, where in 3.2.5 it crashes with a UNIQUE constraint
violation.
What I think is happening is that when adding the employee to the company, in 3.2.2 the
relation is created immediately where in 3.2.5 the relation creation is delayed, leaving
the foreign key of the company to "null". Because modifying the companies is
inside a loop (in the XDoclet generated files) the UNIQUE constraint is violated.
If you check the code generated by XDoclet when adding a new employee, you ll notice that
the "insertAfterEjbPostCreate" would not help since it first creates the
employee with the foreign key to null and then create the relation (which is suppose to
set the foreign key).
Bug could come from something I m doing wrong, but since it works under 3.2.2 and not
3.2.5, I'd like to know in which version the bug is, so that I can found out if my
code is correct.
I hope this description is clear enough.
I can provide the classes of this example if needed.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: