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 with a hasMany relationship between the two
Try and save a relationship
Expected Behaviour
Either an exception should be thrown warning that the many-to-many is misconfigured. (old grails 2 behavior).
Or the relationship data should be saved. (perhaps modeled as two different one-to-many relationships and two different join tables).
Actual Behaviour
No exception is thrown.
In Memory relationship data is stored, and back references are set up along with back references.
No relationship data is stored.
The only real file in the project is a hibernateSpec. The Spec contains two entities with one-to-many mappings to each other.
@EntityclassPerson {
String name
static hasMany = [pets: Pet]
}
@EntityclassPet {
String name
static hasMany = [owners: Person]
}
Here is the test that shows the problem.
void"Expect associations work"() {
given: "A Person and Pet"Person steve =newPerson(name: "steve").save(flush:true, failOnError:true)
Pet spot =newPet(name: "spot").save(flush:true, failOnError:true)
when: "I associate them"
steve.addToPets(spot)
println"Saving... updates the version number on both person and pet, but doesn't write the association data"
steve.save(flush:true, failOnError:true)
println"Flush done."then: "It got persisted in memory"
steve.pets.size()==1
steve.pets[0].name=="spot"and: "back references are set up"
spot.owners.size()==1
spot.owners[0]==steve
when: "if I reload from database"
sessionFactory.currentSession.clear()
Person steve2 =Person.get(steve.id)
then: "those relationships are gone"
steve2.pets.size()==1
steve2.pets[0].name=="spot"
}
I discovered this when I inadvertently tried to create two separate one-to-many relationships between two domain Classes. I was not looking to set up a many-to-many.
My original test didn't clear the session, so loaded the domain items from the hibernate cache, and they still had accesses to the relationships. After the session was cleared the associations just disappeared.
with sql logging turned on, you can verity that even though person/pet are getting the versions updated, no relationship data is stored.
At the very least having the old exception No owner defined between domain classes [class manytomay.Person] and [class manytomay.Pet] in a many-to-many relationship. Example: static belongsTo = manytomay.Pet
would have made my error really obvious.
The text was updated successfully, but these errors were encountered:
Task List
Steps to Reproduce
Expected Behaviour
Either an exception should be thrown warning that the many-to-many is misconfigured. (old grails 2 behavior).
Or the relationship data should be saved. (perhaps modeled as two different one-to-many relationships and two different join tables).
Actual Behaviour
No exception is thrown.
In Memory relationship data is stored, and back references are set up along with back references.
No relationship data is stored.
Environment Information
Example Application
https://github.com/tircnf/manytomany
The only real file in the project is a hibernateSpec. The Spec contains two entities with one-to-many mappings to each other.
Here is the test that shows the problem.
I discovered this when I inadvertently tried to create two separate one-to-many relationships between two domain Classes. I was not looking to set up a many-to-many.
My original test didn't clear the session, so loaded the domain items from the hibernate cache, and they still had accesses to the relationships. After the session was cleared the associations just disappeared.
with sql logging turned on, you can verity that even though person/pet are getting the versions updated, no relationship data is stored.
At the very least having the old exception
No owner defined between domain classes [class manytomay.Person] and [class manytomay.Pet] in a many-to-many relationship. Example: static belongsTo = manytomay.Pet
would have made my error really obvious.
The text was updated successfully, but these errors were encountered: