Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8594667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:15:04+00:00 2026-06-12T00:15:04+00:00

I am creating entities from the database trough the \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory() class. This works perfectly!

  • 0

I am creating entities from the database trough the \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory() class. This works perfectly! Except for the namespace generation. There are no namespaces generated. I am storing my entities in App/Model/Entities.

Does anyone know how to make the generator add namespaces to the entities?

This is the code I use to generate the entities:

<?php
$em->getConfiguration()->setMetadataDriverImpl(
    new \Doctrine\ORM\Mapping\Driver\DatabaseDriver(
        $em->getConnection()->getSchemaManager()
    )
);

$cmf = new \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory();
$cmf->setEntityManager($em);
$metadata = $cmf->getAllMetadata();

// GENERATE PHP ENTITIES!
$entityGenerator = new \Doctrine\ORM\Tools\EntityGenerator(); 
$entityGenerator->setGenerateAnnotations(true); 
$entityGenerator->setGenerateStubMethods(true); 
$entityGenerator->setRegenerateEntityIfExists(false); 
$entityGenerator->setUpdateEntityIfExists(true); 
$entityGenerator->generate($metadata, __dir__. '/Model/Entities");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:15:05+00:00Added an answer on June 12, 2026 at 12:15 am

    I don’t think you can set the namespace when importing from the database, because the EntityGenerator takes the namespace information from the metadata. The database does not have or need namespaces, so the information does not automatically come from there.

    You could try looping over the $metadata object and adding the namespace yourself to class names. The code in the EntityGenerator that retrieves the namespace is quite simple:

    private function _getNamespace(ClassMetadataInfo $metadata)
    {
        return substr($metadata->name, 0, strrpos($metadata->name, '\\'));
    }
    

    If all else fails, you can always implement your own EntityGenerator that you can feed a namespace to use. We did that in our large project, where there are some other custom tasks to be done during generation. However, the EntityGenerator is not easily overriden, lots of private methods and properties so you probably have to copy&paste the whole thing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created a web service in Netbeans; creating the entities classes from my database.
I'm creating some entities (class) for my project and I want to set a
I have two (or more) Java Threads creating, updating and deleting entities from a
Good Day, I'm having few issues with Doctrine entities generator while creating new project
Is there a way to have something like this in doctrine: class Entity {
The Problem: I am working on a WordPress Symfony bundle and creating entities for
I have three entities: Country, State and City with the following relationships: When creating
Creating a class at runtime is done as follows: klass = Class.new superclass, &block
(creating a separate question after comments on this: Javascript redeclared global variable overrides old
When creating an entity framework model from scratch it is possible to specify a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.