question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValidationError: Metadata for entity Object not found

See original GitHub issue

Describe the bug Cannot seem to create a new entity using the repository pattern, not matter how much I try to simplify the entities I always seem to hit this error:

ValidationError: Metadata for entity Object not found

Stack trace

Creating user
{ username: 'admin', password: 'XXXXX', id: '0' }
ValidationError: Metadata for entity Object not found
    at Function.missingMetadata (/Users/johnyick/Documents/code/gitlab/nestjs-boilerplate/node_modules/mikro-orm/dist/utils/ValidationError.js:103:16)
    at MetadataStorage.get (/Users/johnyick/Documents/code/gitlab/nestjs-boilerplate/node_modules/mikro-orm/dist/metadata/MetadataStorage.js:26:43)
    at UnitOfWork.cascade (/Users/johnyick/Documents/code/gitlab/nestjs-boilerplate/node_modules/mikro-orm/dist/unit-of-work/UnitOfWork.js:267:36)
    at UnitOfWork.persist (/Users/johnyick/Documents/code/gitlab/nestjs-boilerplate/node_modules/mikro-orm/dist/unit-of-work/UnitOfWork.js:71:14)
    at EntityManager.persistLater (/Users/johnyick/Documents/code/gitlab/nestjs-boilerplate/node_modules/mikro-orm/dist/EntityManager.js:284:34)
    at EntityManager.persist (/Users/johnyick/Documents/code/gitlab/nestjs-boilerplate/node_modules/mikro-orm/dist/EntityManager.js:267:14)
    at EntityRepository.persist (/Users/johnyick/Documents/code/gitlab/nestjs-boilerplate/node_modules/mikro-orm/dist/entity/EntityRepository.js:9:24)
    at UsersService.create (/Users/johnyick/Documents/code/gitlab/nestjs-boilerplate/dist/core/users/users.service.js:24:37)
    at /Users/johnyick/Documents/code/gitlab/nestjs-boilerplate/dist/core/users/users.controller.js:29:35 {
  entity: undefined,
  name: 'ValidationError'
}

To Reproduce service.ts

    constructor(
        @InjectRepository(User)
        private readonly usersRepository: EntityRepository<User>,
    ) { }

    async create(user: User): Promise<void> {
        return this.usersRepository.persistAndFlush(user);
    }

controller.ts (constructor)

console.log('Creating user');
console.log(ADMIN_USER)
this.usersService.create(ADMIN_USER).then(res => {
    console.log('Created user')
    console.log(res);
}).catch(err => {
    console.error(err);
});

Expected behavior Object to be created as a row within the db table, User. I can see the tables have all created from the migration.

Versions “mikro-orm”: “^3.6.2”, “typescript”: “^3.7.4”,

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
B4nancommented, Apr 6, 2020

You can use repository too, repo.create(payload) is the same.

2reactions
B4nancommented, Apr 6, 2020

You are trying to persist POJO, you need to provide instance of the entity.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trying to persist not discovered entity of type object
Exactly as Micael said, you are trying to persist the DTO instead of entity instance. The type of DTO is plain object, so...
Read more >
MetadataError | API - MikroORM
Inherited from ValidationError.constructor. Type parameters. T: Partial<any> = Partial<any>. Parameters. message: string. optionalentity: T ...
Read more >
error [exceptionshandler] no metadata for - You.com - You.com
EntityMetadataNotFound error is displayed when TypeORM cant find your entities. Often this is caused by wrong/misspelled entry in your ormconfig file. If you ......
Read more >
Handling Errors - FastAPI
Remember all those "404 Not Found" errors (and jokes)? ... 1 validation error path -> item_id value is not a valid integer (type=type_error.integer) ......
Read more >
Database Engine events and errors - SQL Server
This is either because the entity references an object that does not exist or because of an error in one or more statements...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found