TypeOrm与Oracle数据库的多对多关系错误

kqlmhetl  于 2023-04-11  发布在  Oracle
关注(0)|答案(1)|浏览(149)

1.我试图从oracle数据库中检索多对多的关系数据。
1.数据库已经创建,并有大量的数据。
1.数据库结构为:请参见附件database_table_structure
4.我的实体类

@Entity({ name: 'CASEWORKER' })
export class CASEWORKER {
  @PrimaryColumn()
  CASEWORKERID: string;

  @Column()
  CASEWORKERNAME: string;

  @Column()
  ISACTIVE: string;

  @Column()
  TIME_STAMP: Date;

  @ManyToMany(() => CASEWORKERGROUP, (CASEWORKERGROUP) => CASEWORKER_CASEWORKERGROUP)
  @JoinTable()
  CASEWORKERGROUPS: CASEWORKERGROUP[];
}
@Entity({ name: 'CASEWORKERGROUP' })
export class CASEWORKERGROUP {
  @PrimaryColumn()
  CASEWORKERGROUPID: string;

  @Column()
  CASEWORKERGROUPNAME: string;

  @Column()
  TIME_STAMP: Date;

  @ManyToMany(() => CASEWORKER, (CASEWORKER) => CASEWORKER_CASEWORKERGROUP)
  CASEWORKERS: CASEWORKER[];

}
@Entity({ name: 'CASEWORKER_CASEWORKERGROUP' })
export class CASEWORKER_CASEWORKERGROUP {
  @PrimaryColumn()
  CASEWORKERID: string;

  @PrimaryColumn()
  CASEWORKERGROUPID: string;

  @Column()
  TIME_STAMP: Date;
}

1.当我尝试运行该项目时,我得到以下错误-只有当我添加realation标签。

[Nest] 11604  - 08.04.2023 11.53.34   ERROR [TypeOrmModule] Unable to connect to the database (regimeDBConnection). Retrying (1)...
TypeORMError: Entity metadata for **CASEWORKER#CASEWORKERGROUPS** was not found. Check if you specified a correct entity object and if it's connected in the connection options.
    at C:\Development\lbst-api-demo\src\metadata-builder\EntityMetadataBuilder.ts:1089:23
    at Array.forEach (<anonymous>)
    at EntityMetadataBuilder.computeInverseProperties (C:\Development\lbst-api-demo\src\metadata-builder\EntityMetadataBuilder.ts:1079:34)
    at C:\Development\lbst-api-demo\src\metadata-builder\EntityMetadataBuilder.ts:158:18
    at Array.forEach (<anonymous>)
    at EntityMetadataBuilder.build (C:\Development\lbst-api-demo\src\metadata-builder\EntityMetadataBuilder.ts:157:25)
    at ConnectionMetadataBuilder.buildEntityMetadatas (C:\Development\lbst-api-demo\src\connection\ConnectionMetadataBuilder.ts:106:11)
    at DataSource.buildMetadatas (C:\Development\lbst-api-demo\src\data-source\DataSource.ts:685:13)
    at DataSource.initialize (C:\Development\lbst-api-demo\src\data-source\DataSource.ts:253:13)
[Nest] 11604  - 08.04.2023 11.53.34   ERROR [ExceptionHandler] Entity metadata for CASEWORKER#CASEWORKERGROUPS was not found. Check if you specified a correct entity object and if it's connected in the connection options.
v1uwarro

v1uwarro1#

您建立的连接不正确。对于双向关系,您需要指定有效的属性。您需要更改以下内容:

@ManyToMany(() => CASEWORKERGROUP, (CASEWORKERGROUP) => CASEWORKER_CASEWORKERGROUP)
  @JoinTable()
  CASEWORKERGROUPS: CASEWORKERGROUP[];

为此,这里的CASEWORKER_CASEWORKERGROUP应该是指CASEWORKERGROUP实体的有效关系。

@ManyToMany(() => CASEWORKERGROUP, (CASEWORKERGROUP) => CASEWORKERGROUP.CASEWORKERS)
  @JoinTable()
  CASEWORKERGROUPS: CASEWORKERGROUP[];

对于CASEWORKERGROUP实体

@ManyToMany(() => CASEWORKER, (CASEWORKER) => CASEWORKER.CASEWORKERGROUPS)
  CASEWORKERS: CASEWORKER[];

相关问题