Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behavior when using @OneToOne with @MapsId #9100

Closed
1 task
pmverma opened this issue Jan 20, 2019 · 8 comments
Closed
1 task

Inconsistent behavior when using @OneToOne with @MapsId #9100

pmverma opened this issue Jan 20, 2019 · 8 comments
Milestone

Comments

@pmverma
Copy link
Member

pmverma commented Jan 20, 2019

Overview of the issue

I did a PR for adding @MapsId support in #8685 . The related raised issue is #7060.

However, while writing automated tests #9094 I come to know that if you update the child entity with a new parent then this updated new parent will be used for current transaction.
However, in next request, next time if you load the child then it will refer to its parent which was originally mapped.

Motivation for or Use Case

Child should always refers to its correct parent in any case.

Reproduce the error
  1. Generate a new app with current master

  2. Add following entity.json inside .jhipster and regenerate entity with jhipster entity Bar

{
    "fluentMethods": true,
    "clientRootFolder": "",
    "relationships": [
        {
            "relationshipName": "user",
            "otherEntityName": "user",
            "relationshipType": "one-to-one",
            "otherEntityField": "login",
            "ownerSide": true,
            "useJPADerivedIdentifier": true,
            "otherEntityRelationshipName": "bar"
        }
    ],
    "fields": [
        {
            "fieldName": "ddd",
            "fieldType": "String"
        }
    ],
    "changelogDate": "20181231104458",
    "dto": "no",
    "searchEngine": false,
    "service": "serviceImpl",
    "entityTableName": "bar",
    "databaseType": "sql",
    "jpaMetamodelFiltering": false,
    "pagination": "no"
}

  1. Launch the application

  2. Create a new Bar using browser and set user user

  3. Open devtool and go to network tab

  4. Update the Bar to set admin

  5. Check PUT method response body in devtool and u can see the returned bar contains admin

  6. But any new next request such as listing/view/edit will load the correct user

Related issues

#7060
#8685

#9094 WIP

Suggest a Fix
JHipster Version(s)
  • master branch
JHipster Version(s)
mo@0.0.0 /Users/sierra/github/mp
└── (empty)

JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "com.mycompany.myapp"
    },
    "jhipsterVersion": "5.7.2",
    "applicationType": "monolith",
    "baseName": "mo",
    "packageName": "com.mycompany.myapp",
    "packageFolder": "com/mycompany/myapp",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "cacheProvider": "no",
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "postgresql",
    "prodDatabaseType": "postgresql",
    "searchEngine": false,
    "messageBroker": false,
    "serviceDiscoveryType": false,
    "buildTool": "maven",
    "enableSwaggerCodegen": false,
    "jwtSecretKey": "bXktc2VjcmV0LXRva2VuLXRvLWNoYW5nZS1pbi1wcm9kdWN0aW9uLWFuZC10by1rZWVwLWluLWEtc2VjdXJlLXBsYWNl",
    "clientFramework": "angularX",
    "useSass": false,
    "clientPackageManager": "npm",
    "testFrameworks": [],
    "jhiPrefix": "jhi",
    "enableTranslation": false,
    "enableHibernateCache": false,
    "otherModules": []
  }
}
JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
entity Bar {
  ddd String
}
relationship OneToOne {
  Bar{user(login)} to User
}

service Bar with serviceImpl

Environment and Tools

java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)

git version 2.17.2 (Apple Git-113)

node: v10.14.2

npm: 6.4.1

yeoman: 2.0.5

Docker version 18.09.0, build 4d60db4

docker-compose version 1.23.2, build 1110ad01

  • Checking this box is mandatory (this is just to show you read everything)
@pmverma
Copy link
Member Author

pmverma commented Jan 24, 2019

This issue will be solved when hibernate/hibernate-orm#2755 is merged and released. Hoping that PR to be included in next hibernate release.

@pmverma
Copy link
Member Author

pmverma commented Feb 6, 2019

Note: This must also make into v5 maintenance when it is solved.

@DanielFran
Copy link
Member

DanielFran commented Feb 19, 2019

@pmverma the issue has been merged in Hibernate-orm master and should be available only in next 5.4.x release.

V5 is targetting 5.2.x (SB 2.0.x), and V6 is targetting 5.3.x (SB 2.1.x).
So we might need to wait at least Q3 until Spring-boot target 5.4.x in version 2.2.0

@pmverma
Copy link
Member Author

pmverma commented Feb 19, 2019

@DanielFran Yes, it has been merged. Not sure if there is plan to merge in 5.2.x or 5.3.x version. I have asked and have not got reply yet.
Otherwise, I am afraid, our support of @mapsid would not be useful until SprintBoot support 5.4.x.

@pmverma
Copy link
Member Author

pmverma commented Mar 3, 2019

Since the related hibernate fix didn't make into 5.2.x or 5.3.x, we have a few options to still have it(@MapsId) in jhipster.

  1. Warn the users and have it documented as a known issue(not with jhipster itself but with hibernate)

  2. Implement the code so that users won't be able to set new parent if there is already one. (I am not in much favor of this way as this is not related to jhipster but hibernate. And not allowing to set a new parent is something developer should care rather than jhipster )

  3. Keep the feature as a hidden one until SB support 5.4.x.

Important thing to notice here is: AFAIU from Hibernate PR, Hibernate will detect only during merge operation that if the new parent should be set or not. So again, the developer must take care of this when writing the business logic so that wrong association do not effect logic.

@DanielFran @jdubois Let me know your opinion. If there is no any special concern then I would like to go with option no. 1.

@jdubois
Copy link
Member

jdubois commented Mar 4, 2019

@pmverma either 1 or 3 for me. As 1 probably gives less work, and is the one you prefer, let's do it this way.

@pmverma
Copy link
Member Author

pmverma commented Apr 8, 2019

Closing this as #9094 has a workaround for it.

@pmverma pmverma closed this as completed Apr 8, 2019
@jdubois jdubois added this to the 6.0.0 milestone May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants