tircnf opened a new issue, #14359:
URL: https://github.com/apache/grails-core/issues/14359

   ### Task List
   
   - [X] Steps to reproduce provided
   - [X] Stacktrace (if present) provided
   - [X] Example that reproduces the problem uploaded to Github
   - [X] Full description of the issue provided (see below)
   
   ### Steps to Reproduce
   
   1. Create two domain classes.
   2. Make two one-to-many associations between the two objects.
   3.  Try and save a value to the association.
   
   ### Expected Behaviour
   
   Associations should persist to the database.
   
   
   ### Actual Behaviour
   
   The join table that is created has NOT NULL constraints for each association.
   When an insert happens, the NOT NULL constraint for the other association 
fires and prevents the save.
   
   
   ### Environment Information
   
   - **Operating System**: WINDOWS/UNIX
   - **GORM Version:**  7.3.2
   - **Grails Version (if using Grails):** 5.2.3
   - **JDK Version:** 1.8
   
   ### Example Application
   
   https://github.com/tircnf/gormExmple
   
   The example application only has one test spec file, included below.
   When hibernate starts, it creates a single join table for the two 
associations with a
   `person_petsilike_id` column and a `person_petsihate_id` column, both with a 
not-null constraint.
   
   when inserting an association a null constraint fires for the other 
association.
   
   Here is the create table command:
   ```
       create table person_pet (
          person_petsilike_id bigint not null, 
          pet_id bigint, 
          person_petsihate_id bigint not null
       )
   ```
   
   and here is the error when trying to add a pet that I like.
   
   `NULL not allowed for column "PERSON_PETSIHATE_ID"; SQL statement:
   insert into person_pet (person_petsilike_id, pet_id) values (?, ?) 
[23502-200]`
   
   
   ```
   import grails.persistence.Entity
   import grails.test.hibernate.HibernateSpec
   
   class MultiRelationSpec extends HibernateSpec {
   
       @Override
       List<Class> getDomainClasses() {
           [Pet, Person]
       }
   
       def setup() {
       }
   
       def cleanup() {
       }
   
       void "Test setup"() {
           expect: "I can create my local entities"
           new Person(name: "name").save(flush: true, failOnError: true)
           new Pet(name: "name").save(flush: true, failOnError: true)
       }
   
       void "Test adding a relationship"() {
           expect:
           Person p = new Person(name: "person").save()
           Pet friendly = new Pet(name: "friendly").save()
           Pet mean = new Pet(name: "mean")
   
           p.addToPetsILike(friendly)
           p.save(flush:true)
   
       }
    }
   
   
   @Entity
   class Pet {
       String name
   }
   
   @Entity
   class Person {
       String name
   
       static hasMany = [
               petsILike: Pet,
               petsIHate: Pet
       ]
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to