You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Example that reproduces the problem uploaded to Github
Full description of the issue provided (see below)
Steps to Reproduce
Create two domain classes.
Make two one-to-many associations between the two objects.
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.
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
]
}
The text was updated successfully, but these errors were encountered:
tircnf
changed the title
Schema Generation problems with multiple associations against the same object.
Schema Generation creates bad joinTable when multiple associations point to the same type of object.
Sep 14, 2022
Task List
Steps to Reproduce
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
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 aperson_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:
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]
The text was updated successfully, but these errors were encountered: