Doctrine2 Association Persistence

I've been playing around with Zend and Doctrine incorporated into it for the past week or so. I've gotten the hang of basic inserts and selects, and can also use DQL to select from joined tables. The problem I'm having is persisting associated entities. Error I'm getting is this: (path)htdocs\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\MappingException.php:96 with the message 'Class "" does not exist'.

My code is below...

Here is the main entity (the one on the "many" side)

namespace Project\Entity;

use Doctrine\ORM\Mapping as ORM;
use Zend\InputFilter\Factory as InputFactory;

/**
 * ClientUser
 *
 * @ORM\Table()
 * @ORM\Entity
 */
class ClientUser extends SystemUser
{
/**
 * @var integer
 * 
 * @ORM\OneToOne(targetEntity="SystemUser", cascade={"persist", "remove"})
 * @ORM\JoinColumn(name="id", referencedColumnName="id")
 */
private $id;

/**
 * @var integer
 *
 * @ORM\ManyToOne(targetEntity="Client", cascade={"persist", "remove"})
 * @ORM\JoinColumn(name="client", referencedColumnName="id")
 */
private $client;

protected $_inputFilter;

//Other stuff here...
}

Here is the "Client" associated entity...

namespace Project\Entity;

use Doctrine\ORM\Mapping as ORM;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface; 

/**
 * Client
 *
 * @ORM\Table()
 * @ORM\Entity
 */
class Client implements InputFilterAwareInterface
{
/**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var string
 *
 * @ORM\Column(name="client_name", type="string", length=255)
 */
private $clientName;

/**
 * @var integer
 *
 * @ORM\Column(name="loggable_hours", type="integer")
 */
private $loggableHours;

/**
 * @var float
 * 
 * @ORM\Column(name="normal_rate", type="decimal", scale=2)
 */
private $normalRate;

/**
 * @var float
 * 
 * @ORM\Column(name="critical_rate", type="decimal", scale=2)
 */
private $criticalRate;

/**
 * @var string
 *
 * @ORM\Column(name="start_date", type="string")
 */
private $startDate;

/**
 * @var boolean
 *
 * @ORM\Column(name="enabled", type="boolean")
 */
private $enabled;

/**
 * @var integer
 *
 * @ORM\Column(name="critical_hours", type="integer")
 */
private $criticalHours;

/**
 *
 * @var type 
 */
protected $_inputFilter;

//Other stuff (getters,setters, etc)
}

The ClientUser has a one-to-one relationship with the following:

namespace Project\Entity;

use Doctrine\ORM\Mapping as ORM;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface; 

/**
 * SystemUser
 *
 * @ORM\Table()
 * @ORM\Entity
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="user_type", type="integer")
 * @ORM\DiscriminatorMap({1 = "DeveloperUser", 2 = "ClientUser"})
 * 
 */
class SystemUser implements InputFilterAwareInterface {
/**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var string
 *
 * @ORM\Column(name="username", type="string", length=100, unique=true)
 */
private $username;

/**
 * @var string
 *
 * @ORM\Column(name="password", type="string", length=255)
 */
private $password;

/**
 * @var string
 *
 * @ORM\Column(name="user_first_name", type="string", length=255)
 */
private $userFirstName;

/**
 * @var string
 *
 * @ORM\Column(name="user_surname", type="string", length=255)
 */
private $userSurname;

/**
 * @ORM\Column(type="string", length=32)
 */
private $salt;

/**
 * @var \DateTime
 *
 * @ORM\Column(name="last_login", type="datetime")
 */
private $lastLogin = '0000-00-00 00:00:00';

/**
 * @var bool
 * 
 * @ORM\Column(name="enabled", type="boolean", options={"default" = 1})
 */
private $enabled = 1;

/**
 * For the input filter...
 * 
 * @var InputFilter
 */
protected $_inputFilter;

//The rest...
}

I have absolutely no idea what could be wrong here... Just for completeness, here is the controller "add" action...

public function addAction() {
    //To add clients
    $form = new ClientUserForm($this->getServiceLocator()
                                     ->get('Doctrine\ORM\EntityManager'));
    $form->get('submit')->setValue('Add');

    $request = $this->getRequest();
    if ($request->isPost()) {
        $clientUser = new ClientUser();
        $form->setInputFilter($clientUser->getInputFilter());
        $form->setData($request->getPost());

        if ($form->isValid()) {
            $clientUser->populate($form->getData());
            /**
            *This bottom line is where I get the exception!
            */
            $this->getEntityManager()->persist($clientUser);
            $this->getEntityManager()->flush();

            //Redirect
            return $this->redirect()->toRoute('client_user');
        }
    }

    return array ('form' => $form);
}

Any help would be awesome! If I just knew which class "" is supposed to be, I'd probably be in a better place than I am now! Thanks ladies and gents, you guys rock!

EDIT-

Forgot to add these 2 PHP warnings...

Warning: spl_object_hash() expects parameter 1 to be object, integer given in (path)\htdocs\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php on line 1588

Warning: get_class() expects parameter 1 to be object, integer given in (path)\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php on line 1596

Answers


Im not sure of what could be happening, but i find something that i dont understand. When you states the inheritance, you use:

 * @ORM\DiscriminatorColumn(name="user_type", type="integer")
 * @ORM\DiscriminatorMap({1 = "DeveloperUser", 2 = "ClientUser"})

but

  • there isnt a class called DeveloperUser

and also

  • are you sure that in the database, all user_type are just 1 or 2? (no null, not 0, etc)

Need Your Help

SVN avoid storing passwords in plain text?

svn versioning

Under a bare bones setup for SVN on windows (without using VisualSVN), as per the instructions, the passwords are to be entered in the passwd file.