too long

Simple process, Need to create Users with mapped Roles.

I followed the step from link http://symfony.com/doc/current/cookbook/security/entity_provider.html

User and Roles table generated but users_roles table is not generated in MySql... Will i need to create it manually?

Second I have configured with User table for Authentication

After login it redirects to Error page,

FatalErrorException: Error: Call to a member function toArray() on a non-object in /var/www/vibilling_3/src/ViBillingPortal/AuthenticationBundle/Entity/users.php line 130

I searched, but i cant find any solutions... Below my code

Bill/PortalBundle/Entity/users.php

namespace ViBillingPortal\AuthenticationBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\Common\Collections\ArrayCollection;

/**
* users
*/
class users implements UserInterface, \Serializable
{
/**
 * @var integer
 */
private $id;

/**
 * @var string
 */
private $username;

/**
 * @var string
 */
private $password;

/**
 * @var string
 */
private $created_date;

/**
 * @ORM\ManyToMany(targetEntity="roles", inversedBy="users")
 * @ORM\JoinTable(name="user_roles")
 */
private $userroles;


public function __construct()
{
    $this->userroles = new ArrayCollection();
}

/**
 * Get id
 *
 * @return integer 
 */
public function getId()
{
    return $this->id;
}

/**
 * Set username
 *
 * @param string $username
 * @return users
 */
public function setUsername($username)
{
    $this->username = $username;

    return $this;
}

/**
 * Get username
 *
 * @return string 
 */
public function getUsername()
{
    return $this->username;
}

/**
 * Set password
 *
 * @param string $password
 * @return users
 */
public function setPassword($password)
{
    $this->password = $password;

    return $this;
}

/**
 * Get password
 *
 * @return string 
 */
public function getPassword()
{
    return $this->password;
}

/**
 * Set created_date
 *
 * @param string $created_date
 * @return users
 */
public function setCreated_date($password)
{
    $this->password = $created_date;

    return $this;
}

/**
 * Get Created_date
 *
 * @return string 
 */
public function getCreated_date()
{
    return $this->created_date;
}

/**
 * Get Roles
 */
public function getRoles()
{
   return $this->userroles->toArray();
}

/**
 * @inheritDoc
 */
public function getSalt()
{
}

/**
 * @inheritDoc
 */
public function eraseCredentials()
{
}

/**
 * @see \Serializable::serialize()
 */
public function serialize()
{

}

/**
 * @see \Serializable::unserialize()
 */
public function unserialize($serialized)
{

}

}

Bill/PortalBundle/Entity/roles.php

namespace ViBillingPortal\AuthenticationBundle\Entity;

use Symfony\Component\Security\Core\Role\RoleInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

/**
 * roles
 */
class roles implements RoleInterface, \Serializable
{
/**
 * @var integer
 */
private $id;

/**
 * @var string
 */
private $name;

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

/**
 * @ORM\ManyToMany(targetEntity="users", mappedBy="userroles")
 */
protected $users;


public function __construct()
{
    $this->users = new ArrayCollection();
}

/**
 * Get id
 *
 * @return integer 
 */
public function getId()
{
    return $this->id;
}

/**
 * Set name
 *
 * @param string $name
 * @return roles
 */
public function setName($name)
{
    $this->name = $name;

    return $this;
}

/**
 * Get name
 *
 * @return string 
 */
public function getName()
{
    return $this->name;
}

/**
 * @see RoleInterface
 */
public function getRole()
{
    return $this->role;
}

/**
 * @see \Serializable::serialize()
 */
public function serialize()
{

}

/**
 * @see \Serializable::unserialize()
 */
public function unserialize($serialized)
{

}   

}

You should use a ManyToMany relation, not a ManyToOne if you want to use a join table : http://docs.doctrine-project.org/en/2.0.x/reference/association-mapping.html#many-to-many-bidirectional

For the second error, it's strange as you initialize usersroles as an ArrayCollection in your construct method, it should work. Could you add a var_dump to look what is stored in this property ?

Why don't you get any setter/getter for usersroles ?

I think you should also read Symfony coding standards : http://symfony.com/doc/current/contributing/code/standards.html. You coding style is not consistent.