-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: @ManytoOne causing transient instance - save Exception
PostPosted: Thu Aug 04, 2011 2:24 pm 
Newbie

Joined: Fri Aug 18, 2006 6:47 am
Posts: 11
I am doing using JPA annotations only, with Hibernate as the provider on all my Entities.

I am getting a problem with my @ManyToOne relationships saying that the "object references an unsaved transient instance - save the transient instance before flushing:"

here are my two classes:

Code:
@Entity
@Table(name = "MY_CONFIG")
public class MyConfig {

              @Id           
   @GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "CONFIG_SEQ")
   @SequenceGenerator(name="CONFIG_SEQ", sequenceName = "CONFIG_SEQ")
   @Column(name = "CONFIG_ID")
   private Long configId;   
           
   @ManyToOne(fetch=FetchType.LAZY)
   @JoinColumn(name="REG_ACTION_ID")
   private MyRegAction myRegAction;


}


@Table(name = "MY_REG_ACTION")
public class MyRegAction {

             @ID
   @GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "REG_ID")
   @SequenceGenerator(name="REG_ID", sequenceName = "REG_ID")
   @Column(name = "REG_ACTION_ID")
             private Long regActionId;

            @OneToMany(mappedBy="myRegAction", cascade = CascadeType.ALL)
   private List<MyConfig> regConfig;



Its an oracle DB with a sequence generated for both Objects. If I don't specifically set the ID in my Unit test for the MyRegAction I get the following error:

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

INFO at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:219)
INFO at org.hibernate.type.EntityType.getIdentifier(EntityType.java:397)
INFO at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:242)
INFO at org.hibernate.type.TypeFactory.findDirty(TypeFactory.java:597)
INFO at org.hibernate.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:3128)
INFO at org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:479)
INFO at org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:204)
INFO at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:127)
INFO at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
INFO at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
INFO at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
INFO at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
INFO at xxx.HibernateDaoImpl.flush(HibernateDao.java:490)
INFO at ConfigDAOTest.readMConfig(ConfigDAOTest.java:51)
INFO at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
INFO at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
INFO at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
INFO at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
INFO at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
INFO at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
INFO at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
INFO


Obviously I shouldn't need to set any Id in my tests as they are all sequence generated Ids....so what is wrong?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.