ValidationError: Metadata for entity Object not found
See original GitHub issueDescribe 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:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can use repository too,
repo.create(payload)
is the same.You are trying to persist POJO, you need to provide instance of the entity.