-->
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.  [ 3 posts ] 
Author Message
 Post subject: No row with the given identifier exists
PostPosted: Fri Jan 17, 2014 8:29 am 
Newbie

Joined: Fri May 22, 2009 3:35 am
Posts: 5
Hi, I have problem since hibernate 4.1.8 with this exception

org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [test.hibernate.TestPrepravkaOsobaSAdresou$Uvazek#2]

I have simple OneToMany association between two entities:

Code:
  @Entity(name = "Ppv")
  @Table(name = "PPV")
  public static class Ppv {

    @Id
    Long ppvId;
   
    @OneToMany(fetch = FetchType.EAGER, mappedBy = "ppv")
    Set<Uvazek> uvazeks = new HashSet<Uvazek>(0);
  }


Code:
@Entity(name = "Uvazek")
  @Table(name = "UVAZEK")
  public static class Uvazek {
   
    @Id
    Long uvazekId;
   
    @ManyToOne
    @JoinColumn(name = "PPV_FXID")
    Ppv ppv;

  }


and test case where I have one Ppv and two Uvazek. When I load and detach Ppv, delete one Uvazek associated with loaded Ppv and merge Ppv I get an exception.

Code:
jdbcTemplate.execute("insert into PPV values(1)");
jdbcTemplate.execute("insert into UVAZEK values(2, 1)");
jdbcTemplate.execute("insert into UVAZEK values(3, 1)");

Ppv ppv = (Ppv) getSession().get(Ppv.class, 1l);
getSession().clear();
   
getSession().delete(getSession().get(Uvazek.class, 2l));
getSession().flush();
getSession().merge(ppv);
getSession().flush();             //cause exception


Hibernate during Ppv merge try to load deleted Uvazek. But Uvazek is deleted. Hibernate has information about it in org.hibernate.collection.internal.AbstractPersistentCollection.storedSnapshot on uvazeks set on detached Ppv. In previous version (<4.1.8) this works. In this simple example I can repair it by adding orphanRemoval=true on uvazeks set on Ppv and instead of deleting uvazek remove it from uvazeks set on Ppv.

So my question is: Is this hibernate bug or my bad practise?


Top
 Profile  
 
 Post subject: Re: No row with the given identifier exists
PostPosted: Thu Jan 23, 2014 7:13 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
I think the flush-merge-flush sequence you do is very strange, and not really understanding why you'd ever want to do such an operation.
Still, I also don't see why you would get an exception, so it might be an issue in Hibernate.

You're using a fairly old version of Hibernate, could you update to 4.2.8.Final and try it there? It should be a drop-in replacement (fully backwards compatible with 4.1.8)

http://hibernate.org/orm/downloads/

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: No row with the given identifier exists
PostPosted: Mon Jan 27, 2014 3:56 am 
Newbie

Joined: Fri May 22, 2009 3:35 am
Posts: 5
Hi, thanks for answer.

This flush-merge-flush is simple example which cause that exception (since hibernate version 4.1.8). I try to extract problem to simple example. For example the first flush may be trigged by autoflush before some select and second flush is called on the end of the transaction.

Version 4.1.7 we use because any other version contains this problem.

And why this exception?

Code:
*1 Ppv ppv = (Ppv) getSession().get(Ppv.class, 1l);
*2 getSession().clear();

*3 //send Ppv to client for some modification   

*4 getSession().delete(getSession().get(Uvazek.class, 2l));
*5 getSession().flush();
*6 getSession().merge(ppv);
*7 getSession().flush();             //cause exception


On line 1 I load Ppv with collection uvazeks which contains two Uvazek. Hibernate holds in org.hibernate.collection.internal.AbstractPersistentCollection.storedSnapshot information about this two Uvazek.
On line 2 I detach Ppv (send entity co the client).
On line 4 I delete one Uvazek (which is allready associated with Ppv from line 1)
On line 6 during merge hibernate tries to load deleted Uvazek (he knows it about it from org.hibernate.collection.internal.AbstractPersistentCollection.storedSnapshot) from database. This cause my exception.

It is not such unusual usecase. Or is it?


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