0

I am being plagued by an

org.hibernate.TransientObjectException

using Grails 2.3.9 and Grails Hibernate 3 Plugin 3.6.10.15

Here's the specific issue:

I have a domain class called Pencil and a domain class Backpack with a many-to-many relationship:

 Pencil{
    PencilType type
    Location location
    Date creationDate
    String description
    int position
    boolean active

    static hasMany = [backpacks: BackPack]
    static belongTo = [backpacks: BackPack]

    static constraints = { .... all nullable ..... }
 }

 BackPack{
    Color color
    int size

    static hasMany = [pencils: Pencil]
    static belongsTo = [pencils: Pencil]

    static constraints = { .... all nullable ..... }
  }

If I create and save a pencil, I cannot save without getting the:

org.hibernate.TransientObject Exception
Message: object references an unsaved transient instance - save the transient instance before flushing: Pencil

This occurs even when creating a blank pencil object.

 new Pencil().save()

--UPDATE-- **Problem occurs using both Hibernate3 and Hibernate4 Grails plugin.

Brandon Wagner
  • 893
  • 9
  • 27

1 Answers1

0

Try making sure you have properly demarcated your transactional boundaries with @Transactional or withTransaction for write operations.

Graeme Rocher
  • 7,985
  • 2
  • 26
  • 37
  • In the service where I'm saving, I have static transactional = true and I just tested using @Transactional annotations and it still throws the transient instance exception. I rolled Grails back from 2.3.9 to 2.2.5 and it saves fine. – Brandon Wagner Jun 05 '14 at 01:32
  • Also, I'm trying to upgrade to hibernate 4 to make sure it's not a hibernate 3 bug or something. However, I'm getting an error when using hibernate4. I've put up another question regarding that issue: http://stackoverflow.com/questions/24050291/grails-hibernate4-upgrade – Brandon Wagner Jun 05 '14 at 01:44