Skip to content

Importing jdl doesn't edit OnModelCreating method for relationship #1517

@zahasoftware

Description

@zahasoftware
Overview of the issue

I have a problem when I run the app after jdl file is imported, It doesn't edit OnModelCreation Method to define relationship and cannot be executed

NOTE: It works well if I don't import jdl file.

Motivation for or Use Case

I was so close show to the company how to create fastest project using jhipster-dotnetcore

Reproduce the error

Create a monolitic app in mysql then import the jdl (below), then run application

Log

2024-10-28 22:39:23.716 FATL 24672 --- [  1] Program                                  : Host terminated unexpectedly
System.InvalidOperationException: The dependent side could not be determined for the one-to-one relationship between 'Person.PresentationPage' and 'PresentationPage.Person'. To identify the dependent side of the relationship, configure the foreign key property. If these navigations should not be part of the same relationship, configure them independently via separate method chains in 'OnModelCreating'. See https://go.microsoft.com/fwlink/?LinkId=724062 for more details.
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.ValidateRelationships(IModel model, IDiagnosticsLogger`1 logger)
Related issues

N

Suggest a Fix

N

JHipster Version(s)

8.1.0

JHipster configuration

Monolitic
Mysql

Entity configuration(s) entityName.json files generated in the .jhipster directory

WARNING! Since JHipster v8, the jhipster command will not use the locally installed generator-jhipster.
If you want to execute the locally installed generator-jhipster, run: npx jhipster
INFO! No custom commands found within blueprint: generator-jhipster-dotnetcore at C:\Projects\jhipster\netcore-test-mysql-monolite\node_modules\generator-jhipster-dotnetcore

    ██╗ ██╗   ██╗ ████████╗ ███████╗   ██████╗ ████████╗ ████████╗ ███████╗
    ██║ ██║   ██║ ╚══██╔══╝ ██╔═══██╗ ██╔════╝ ╚══██╔══╝ ██╔═════╝ ██╔═══██╗
    ██║ ████████║    ██║    ███████╔╝ ╚█████╗     ██║    ██████╗   ███████╔╝

██╗ ██║ ██╔═══██║ ██║ ██╔════╝ ╚═══██╗ ██║ ██╔═══╝ ██╔══██║
╚██████╔╝ ██║ ██║ ████████╗ ██║ ██████╔╝ ██║ ████████╗ ██║ ╚██╗
╚═════╝ ╚═╝ ╚═╝ ╚═══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══════╝ ╚═╝ ╚═╝
https://www.jhipster.tech
Welcome to JHipster v8.1.0

Welcome to the JHipster Information Sub-Generator

netcore-test-mysql-monolite@ C:\Projects\jhipster\netcore-test-mysql-monolite
├─┬ [email protected]
│ └── [email protected] deduped
└── [email protected]
JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "applicationType": "monolith",
    "authenticationType": "jwt",
    "baseName": "netcoreTestMysqlMonolite",
    "blueprints": [
      {
        "name": "generator-jhipster-dotnetcore",
        "version": "4.1.0"
      }
    ],
    "clientFramework": "react",
    "clientTestFrameworks": [],
    "clientTheme": "darkly",
    "clientThemeVariant": "dark",
    "cqrsEnabled": false,
    "creationTimestamp": 1728591745222,
    "databaseType": "mysql",
    "devServerPort": 9060,
    "enableTranslation": false,
    "entities": [
      "Person",
      "Service",
      "Payment",
      "PresentationPage",
      "Comment"
    ],
    "jhipsterVersion": "8.1.0",
    "lastLiquibaseTimestamp": 1728592045000,
    "microfrontend": null,
    "microfrontends": [],
    "namespace": "NetcoreTestMysqlMonolite",
    "nativeLanguage": "en",
    "serverPort": "5000",
    "testFrameworks": [],
    "withAdminUi": true,
    "withTerraformAzureScripts": null
  }
}
Environment and Tools

'java' command could not be found

git version 2.47.0.windows.1

node: v20.17.0
npm: 10.9.0

Docker version 27.2.0, build 3ab4256

JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
@ChangelogDate("20241010202325")
entity Person {
  name String required
  email String required
  phone String
  bio String
}
@ChangelogDate("20241010202425")
entity Service {
  name String required
  description String required
  price BigDecimal required
  available Boolean required
}
@ChangelogDate("20241010202525")
entity Payment {
  amount BigDecimal required
  paymentDate Instant required
  paymentMethod String required
}
@ChangelogDate("20241010202625")
entity PresentationPage {
  title String required
  description String required
  published Boolean required
}
@ChangelogDate("20241010202725")
entity Comment {
  content String required
  commentDate Instant required
}
relationship OneToOne {
  Person{presentationPage} to PresentationPage{person}
}
relationship OneToMany {
  Person{services} to Service{person}
  PresentationPage{comments} to Comment{presentationPage}
}
relationship ManyToOne {
  Payment{person} to Person
  Comment{person} to Person
}

paginate Service, Payment with pagination
paginate Comment with infinite-scroll

Congratulations, JHipster execution is complete!
If you find JHipster useful consider sponsoring the project https://www.jhipster.tech/sponsors/

Thanks for using JHipster!

ApplicationContext

protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            // Rename AspNet default tables
            builder.Entity<User>().ToTable("Users");
            builder.Entity<Role>().ToTable("Roles");
            builder.Entity<UserRole>().ToTable("UserRoles");
            builder.Entity<IdentityUserClaim<string>>().ToTable("UserClaims");
            builder.Entity<IdentityUserLogin<string>>().ToTable("UserLogins");
            builder.Entity<IdentityRoleClaim<string>>().ToTable("RoleClaims");
            builder.Entity<IdentityUserToken<string>>().ToTable("UserTokens");

            builder.Entity<UserRole>(userRole =>
            {
                userRole.HasKey(ur => new { ur.UserId, ur.RoleId });

                userRole.HasOne(ur => ur.Role)
                    .WithMany(r => r.UserRoles)
                    .HasForeignKey(ur => ur.RoleId)
                    .IsRequired();

                userRole.HasOne(ur => ur.User)
                    .WithMany(r => r.UserRoles)
                    .HasForeignKey(ur => ur.UserId)
                    .IsRequired();
            });

            builder.Entity<User>()
                .HasMany(e => e.UserRoles)
                .WithOne()
                .HasForeignKey(e => e.UserId)
                .IsRequired()
                .OnDelete(DeleteBehavior.Cascade);

        }
Browsers and Operating System

Windows 11

  • [ X] Checking this box is mandatory (this is just to show you read everything)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions