Details
Description
Hi everyone!
I'm having a problem with the optimistic locking feature. I have this (simplified) model tree:
- BaseElement (abstract)
- Element (abstract)
- Entity (abstract)
- Person (abstract)
- Contact
- BusinessPartner (abstract)
- Customer
- Lead
- Person (abstract)
- Entity (abstract)
- Element (abstract)
Now, with MySQL Logging active, when I update a Lead I have these queries executed:
Query START TRANSACTION Query SELECT ...Lead fields... WHERE id = 123 Query UPDATE business_partner SET ...BusinessPartner fields... WHERE id = 123 Query UPDATE element SET version = version + 1 WHERE id = 123 AND version = 1 Query commit
It works perfectly. The same goes when I update a Customer. The problem comes when I want to update a Contact:
Query START TRANSACTION Query SELECT ...Contact fields... WHERE id = 123 Query UPDATE element SET version = version + 1 WHERE id = 123 AND version = 1 Query UPDATE person SET ...Person fields... WHERE id = 123 Query commit
As you can see, the element row (and the version checking) occurs before the update of the person row. I think this is the reason I'm getting an OptimisticLockingException. Maybe after the Person row is updated, version is being checked again? I can't figure out why. My simplified model basically is like this:
BaseElement:
/**
* @orm:MappedSuperclass
*/
abstract class BaseElement
{
// ID, Version and other fields
}
Element:
/**
* @orm:Entity(repositoryClass="ENC\Bundle\ElementModuleBundle\Entity\ElementRepository")
* @orm:Table(name="element")
* @orm:InheritanceType("JOINED")
* @orm:DiscriminatorColumn(name="discriminator", type="string")
* @orm:DiscriminatorMap({
"contact" = "CNE\Bundle\ContactModuleBundle\Entity\Contact",
"lead" = "CNE\Bundle\LeadModuleBundle\Entity\Lead",
"customer" = "CNE\Bundle\CustomerModuleBundle\Entity\Customer",
})
abstract class Element extends BaseElement
{
// Other fields
}
Entity:
/**
* @orm:Entity(repositoryClass="ENC\Bundle\EntityModuleBundle\Entity\EntityRepository")
* @orm:Table(name="entity")
*/
abstract class Entity extends Element
{
// Fields
}
BusinessPartner:
/**
* @orm:Entity(repositoryClass="ENC\Bundle\BusinessPartnerModuleBundle\Entity\BusinessPartnerRepository")
* @orm:Table(name="business_partner")
*/
abstract class BusinessPartner extends Entity
{
// Fields
}
Person
/**
* @orm:Entity(repositoryClass="ENC\Bundle\PersonModuleBundle\Entity\PersonRepository")
* @orm:Table(name="person")
*/
abstract class Person extends Entity
{
// Fields
}
Contact:
/**
* @orm:Entity(repositoryClass="ENC\Bundle\ContactModuleBundle\Entity\ContactRepository")
* @orm:Table(name="contact")
* @orm:HasLifecycleCallbacks
*/
class Contact extends Person
{
// Fields
}
Lead:
/**
* @orm:Entity(repositoryClass="ENC\Bundle\LeadModuleBundle\Entity\LeadRepository")
* @orm:Table(name="lead")
* @orm:HasLifecycleCallbacks
*/
class Lead extends BusinessPartner
{
// Fields
}
Customer:
/**
* @orm:Entity(repositoryClass="ENC\Bundle\CustomerModuleBundle\Entity\CustomerRepository")
* @orm:Table(name="customer")
* @orm:HasLifecycleCallbacks
*/
class Customer extends BusinessPartner
{
// Fields
}
I don't post the annotations of all my models because they're too many and I think they don't have nothing to do with the problem. But in case you need them, please, tell me and I post them ![]()
Thanks in advance!
Activity
| Field | Original Value | New Value |
|---|---|---|
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Fix Version/s | 2.0.3 [ 10117 ] | |
| Fix Version/s | 2.1 [ 10022 ] | |
| Resolution | Fixed [ 1 ] |
| Fix Version/s | 2.0.4 [ 10130 ] | |
| Fix Version/s | 2.1 [ 10022 ] | |
| Fix Version/s | 2.0.3 [ 10117 ] |
| Workflow | jira [ 12438 ] | jira-feedback [ 14779 ] |
| Workflow | jira-feedback [ 14779 ] | jira-feedback2 [ 16643 ] |
| Workflow | jira-feedback2 [ 16643 ] | jira-feedback3 [ 18896 ] |
- Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-1052, expand=changesets[-21:-1].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)
Can you post the stack trace of the optimistic version exception?
In general This inheritance hierachy scares the hell out of me, why do you need 5 levels of inheritance? Cant you just drop BaseElement, element and Entity into one? Plus this model really fails What happens if a person moves from a lead to customer or contact or back?