-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate save an object twice
PostPosted: Wed Apr 19, 2017 8:28 am 
Newbie

Joined: Mon Mar 06, 2017 9:15 am
Posts: 18
I encountered a strange problem while trying to save objects into Database.

I have a collection like this.

Code:
@OneToMany (fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true, mappedBy ="article")
private List<Element> elements = new ArrayList<>();

And for the sake of bidirectional relationship, in
Quote:
Element
class :
Code:
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn (name="i_article")
protected Article article;


And this is my saving method :
Code:
tx = session.beginTransaction();
session.merge(art);
session.flush();
tx.commit();


The problem is, when i tried to save a new instance, Hibernate saves that instance twice in the database, one with Collection, one without the Collection. I tried
Quote:
saveAndUpdate
and its still the same. When i tried to edit , as well as add elements to an existing instance, it works well.

Can anyone explain this ?


Top
 Profile  
 
 Post subject: Re: Hibernate save an object twice
PostPosted: Wed Apr 19, 2017 8:33 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Sounds like HHH-5855 Jira issue.

You need to upgrade to 5.2.10 or 5.0.8. I don't think it's fixed in 3.x or 4.x branches.


Top
 Profile  
 
 Post subject: Re: Hibernate save an object twice
PostPosted: Wed Apr 19, 2017 9:30 am 
Newbie

Joined: Mon Mar 06, 2017 9:15 am
Posts: 18
vlad wrote:
Sounds like HHH-5855 Jira issue.

You need to upgrade to 5.2.10 or 5.0.8. I don't think it's fixed in 3.x or 4.x branches.


Hi,

I am currently using 5.0.11 , could that still be a problem. Meanwhile im trying to migrate it into the newest version :D


Top
 Profile  
 
 Post subject: Re: Hibernate save an object twice
PostPosted: Wed Apr 19, 2017 10:13 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I guess it should not replicate on 5.0.11. Just give it a try with 5.2.10 and see if you can replicate it there.


Top
 Profile  
 
 Post subject: Re: Hibernate save an object twice
PostPosted: Wed Apr 19, 2017 3:29 pm 
Newbie

Joined: Mon Mar 06, 2017 9:15 am
Posts: 18
I may have an idea why, its because my application, thanks anyway


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