Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6134545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:22:08+00:00 2026-05-23T17:22:08+00:00

Basic problem: I’ve got a many to many relationship (Stores, Products) with a lookup

  • 0

Basic problem: I’ve got a many to many relationship (Stores, Products) with a lookup entity named ProductOffering. In the situation where I have a persistent StoreLocation and try to attach transient Products, hibernate complains EVEN THOUGH I DON’T WANT TO SAVE YET.

Questions:

  1. Why is grails/gorm/Hibernate trying to save my entity?
  2. Is there a better way to approach this problem?

My domain classes look like this:

class StoreLocation {
    String name
    List offerings
    static hasMany = [offerings:ProductOffering]
    static constraints = {
    }
}

class Product {
    String name
    static hasMany = [offeredBy:ProductOffering]
    static constraints = {
        name(unique:true)
        offeredBy(nullable:true)
    }
}

class ProductOffering {
    static belongsTo = [product:Product, store:StoreLocation]
    static constraints = {
    }
}

And my StoreLocationController “edit” action looks like this.

def edit = {
    //get the store we want to edit
    def storeLocation = StoreLocation.get(params.id)
    //create a transient product and add it to the store
    // by attaching it to a transient productOffering
    def product = new Product()
    def offering = new ProductOffering()
    offering.product = product
    storeLocation.addToOfferings(offering)
    //render the edit page
    render(view:"edit", model:[storeLocation:storeLocation])
}

Assume I’ve got a storeLocation with ID=1. I go to edit the StoreLocation
localhost:8080/myapp/storeLocation/edit/1

It doesn’t matter what my view looks like. It could be

hello

I get the following error.

Error 500: not-null property references a null or transient value: ProductOffering.product; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: ProductOffering.product

The stack trace is not much more useful:

org.springframework.dao.DataIntegrityViolationException: not-null property references a null or transient value

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:22:10+00:00Added an answer on May 23, 2026 at 5:22 pm

    Grails registers an OpenSessionInView interceptor around all requests. This ensures that a Hibernate session is open for the duration of each request, and the session is flushed and closed at the end of the request. This has the benefit of avoid lazy loading exceptions.

    Since the session is flushed at the end of the request, any dirty persistent instances are pushed to the database, and that’s what’s happening here. You load the storeLocation instance and change it, so that change is flushed. You don’t need to save the ProductOffering since that will be transitively saved when the storeLocation is flushed, but the Product instance isn’t, so you get this exception.

    The simple fix if you don’t want any changes to be persisted is to remove the changed instance from the persistence context – do this by calling storeLocation.discard() before the render call. See http://grails.org/doc/latest/ref/Domain%20Classes/discard.html for information on the discard method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic problem but Google is not yielding many results for me
I'm sure I've got a basic problem in my C knowledge. I have one
I have such a basic problem in Delphi,I can't solve it. My Code: Note:DataR
So I have a rather basic javascript problem which I have been slamming my
I have a very basic texture map problem in GL on iPhone, and I'm
The problem is quite basic. I have a JTable showing cached data from a
I think I have a synchronization problem...It may be too basic..Please help.. I have
The basic problem I'm trying to solve is that I have a mix of
I have a basic problem with a has_one and belongs_to association. I have two
I have a seemingly basic problem with C# arrays. I am a beginner, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.