1 Reply Latest reply on Jun 18, 2008 7:40 PM by kleinerroemer

    ManyToOne org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing

    kleinerroemer

      Hey Guys!


      This is more a hibernate problem than a seam problem but I hope you have some ideas!


      I've got to classes referencing each other like this:


      Class A:



             @Id 
              @GeneratedValue
              @Basic
              protected long id;
      
              @Basic
              @Column(unique=true)
              protected String extern_id;
      
              @ManyToOne
              @Nullable
              protected B b;
      



      Class B:


              @Id 
              @GeneratedValue
              @Basic
              protected long id;
      
              @Basic
              @Column(unique=true)
              protected String extern_id;
      
              @OneToMany
              protected List<A> a;
      




      In my Import script (import-dev.sql) im Inserting some values for a:


      insert into A (extern_id) values ('8812948')
      insert into A (extern_id) values ('1254123')



      If I now try to load A with this query:


      em.createQuery( "from A a where a.extern_id = :eid" ).setParameter( "eid", eid ).getSingleResult();



      by extern id it, works fine for the first one, but not for the second one. If I remove the second one, the error gets thrown while loading the first one.
      If I try to load A by its' natural id, it works fine.


      There is absolutely no difference between the two entries.


      It is also not working, if I set b id for a!


      I won't provide the full stack trace here, since it is very long, and not telling anything intresting (at least from my point of view).


      I hope you have some ideas!


      Greets

        • 1. Re: ManyToOne org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing
          kleinerroemer

          that the error looks like:



          Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: A.b -> B
                  at org.hibernate.engine.CascadingAction$9.noCascade(CascadingAction.java:353)
                  at org.hibernate.engine.Cascade.cascade(Cascade.java:139)
                  at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:131)
                  at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:122)
                  at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
                  at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
                  at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
                  at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
                  at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
                  at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:80)