-->
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.  [ 7 posts ] 
Author Message
 Post subject: help with unidirectional one-to-many association
PostPosted: Thu Dec 15, 2005 4:18 am 
Newbie

Joined: Fri Oct 17, 2003 5:09 am
Posts: 13
Location: Madrid, Espa
Hello,

I've got an unidirectional one-to-many association on a join table like the example of the documentation.

Hibernate version: 3.0.5

Mapping documents:
Code:
<class name="Person">
<id name="id" column="personId">
<generator class="native"/>
</id>
<join table="PersonAddress"
optional="true">
<key column="personId" unique="true"/>
<many-to-one name="address"
column="addressId"
not-null="true"/>
</join>
</class>
<class name="Address">
<id name="id" column="addressId">
<generator class="native"/>
</id>
</class>


These are the tables:
Code:
create table Person ( personId bigint not null primary key )
create table PersonAddress ( personId not null, addressId bigint not null primary key )
create table Address ( addressId bigint not null primary key )


when i insert a Person works fine (personId is null), insert Person and insert in the join table.
But I want to update a "Person" (personId is not null) without an "Address". (That "Address" is not in the ddbb).


In the same hibernate session call:

Code:
session.save(address) // then I save the address in the data base
person.setAddress(address) // first of all I assign that address to a Person 
session.saveOrUpdate(person) // later I saveOrUpdate the Person.


As a result of that saveOrUpdate, hibernate updates "Person" and tries to update the join table when what I need is an insert.

I get this:

Code:
Hibernate: select this_.addressId as (...)
[14/12/05 16:00:02:322 CET] 46039ce0 SystemOut     O INFO - Address not found in DDBB...
[14/12/05 15:27:43:474 CET] 5a331007 SystemOut     O Hibernate: update Person set (...) where personId=?
[14/12/05 15:27:43:489 CET] 5a331007 SystemOut     O Hibernate: delete from PersonAddress where personId=?
[14/12/05 15:27:43:520 CET] 5a331007 SystemOut     O Hibernate: update PersonAddress set addressId=? where personId=?
[14/12/05 15:27:43:599 CET] 5a331007 SystemOut     O ERROR - Could not synchronize database state with session
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: ADDRESS
   at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:216)
   at org.hibernate.type.EntityType.getIdentifier(EntityType.java:99)
   at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:63)
   at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1617)
   at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:1963)
   at org.hibernate.persister.entity.BasicEntityPersister.updateOrInsert(BasicEntityPersister.java:1909)
   at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:2149)
   at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:75)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:137)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
   at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:584)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:496)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:469)
   at org.springframework.transaction.interceptor.TransactionAspectSupport.doCommitTransactionAfterReturning(TransactionAspectSupport.java:266)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
   at $Proxy1.savePago(Unknown Source)
   at iam.pagos.web.controllers.NewPagoFormController.onSubmit(NewPagoFormController.java:163)
   at org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:258)
   at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:259)
   at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:139)
   at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:717)
   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:658)
   at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:392)
   at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:357)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
   at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
   at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
   at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
   at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
   at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
   at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
   at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
   at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:76)
   at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:118)
   at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:52)
   at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:132)
   at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:71)
   at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:132)
   at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:71)
   at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:974)
   at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:564)
   at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
   at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
   at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
   at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
   at com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java:116)
   at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:186)
   at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
   at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
   at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
   at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
   at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:672)



thaks in advance,
César.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 16, 2005 12:55 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi

Did u use session.flush() ?
once you inserted the address using session.save(address).

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 16, 2005 4:33 am 
Newbie

Joined: Fri Oct 17, 2003 5:09 am
Posts: 13
Location: Madrid, Espa
Hi ramnath,

Thanks for your help but I tried that and it didn't work either. I have the same exception.


Top
 Profile  
 
 Post subject: I have the same problem
PostPosted: Fri Mar 28, 2008 12:21 pm 
Newbie

Joined: Fri Mar 28, 2008 12:06 pm
Posts: 4
Hi,
I'm having the same problem.
Did you find a solution for this?

I did not try it yet, but do merge or version get into this picture?
http://forum.hibernate.org/viewtopic.ph ... 32f981439a

Help wanted,
JN


Top
 Profile  
 
 Post subject: I have the same problem
PostPosted: Fri Mar 28, 2008 12:21 pm 
Newbie

Joined: Fri Mar 28, 2008 12:06 pm
Posts: 4
Hi,
I'm having the same problem.
Did you find a solution for this?

I did not try it yet, but do merge or version get into this picture?
http://forum.hibernate.org/viewtopic.ph ... 32f981439a

Help wanted,
JN


Top
 Profile  
 
 Post subject: I have the same problem
PostPosted: Fri Mar 28, 2008 12:33 pm 
Newbie

Joined: Fri Mar 28, 2008 12:06 pm
Posts: 4
Hi,
I'm having the same problem.
Did you find a solution for this?

I did not try it yet, but do merge or version get into this picture?
http://forum.hibernate.org/viewtopic.ph ... 32f981439a

Help wanted,
JN


Top
 Profile  
 
 Post subject: I have the same problem
PostPosted: Fri Mar 28, 2008 12:51 pm 
Newbie

Joined: Fri Mar 28, 2008 12:06 pm
Posts: 4
Hi,
I'm having the same problem.
Did you find a solution for this?

I did not try it yet, but do merge or version get into this picture?
http://forum.hibernate.org/viewtopic.ph ... 32f981439a

Help wanted,
JN


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

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.