-->
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.  [ 2 posts ] 
Author Message
 Post subject: Persisting a new child executes a new select on parent
PostPosted: Wed Mar 06, 2013 1:05 am 
Regular
Regular

Joined: Tue Feb 19, 2008 6:05 pm
Posts: 82
Transient child (using new Child and child.setParent(parent)) persistence created out of a detached parent (hibTemplate.find("from Parent")) does a separate select on each parent when inserting child.

Tried both bidrectional mapping with mappedBy on OneToMany side to make it bidrectional and also a separate mapping to make it unidirectional after removing mappedBy.

Also tried selecting parent from statless and stateful sessions. Nothing stops from running a separate select on the parent when persisting child.

Code:
Parent A:

    private CompositeId id;
    private List<B> bs;

    @OneToMany // (mappedBy=true) // bidirectional
    // or non bidrectional, neith works
    @JoinColumns({@JoinColumn(name=A_1, insertable=false, updateable=false),
        @JoinColumn(A_2), insertable=false, updateable=false})
    public List<B> getBs(){
        return bs;
    }


Child B:
   
    @Id
    public int getIdentityId(){
        return identityId;
    }

    @OneToMany
    @JoinColumns({@JoinColumn(name=A_1, insertable=false, updateable=false),
        @JoinColumn(A_2), insertable=false, updateable=false})
    public A getA(){
         return a;
    }


Top
 Profile  
 
 Post subject: Re: Persisting a new child executes a new select on parent
PostPosted: Mon Mar 11, 2013 1:01 am 
Regular
Regular

Joined: Tue Feb 19, 2008 6:05 pm
Posts: 82
Beginning to realize that in our Spring batch application, although parent source returns detached objects using stateless session which is flushed and cleared well by Spring batch reader itself, the overall transaction boundary encompasses both the parent object reader and persistence in our dao where we persist new transient collections associated with this detached parent. Hibernate is trying to fetch its parent again to confirm this parent exists because of the bi directional relationship and the only solution I see is creating a proxy out of this parent while persisting children yet again :(.

I was also assuming making insertable=false on OneToMany annotation and setting optional=true, then persisting by separate column mapping will not check, but that is not the case at all. Its doing a separate select of the parent just before the spring batch transaction boundary commits/flushes.

Isn't there any ways of mentioning that the relationship is just for join purpose and nothing else??


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.