-->
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.  [ 12 posts ] 
Author Message
 Post subject: No row with the given identifier exists
PostPosted: Tue Nov 22, 2005 3:04 pm 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
Hibernate version: 3.0


Hello guys,

I'm getting the following error:

Code:
java.lang.RuntimeException: org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [auge.bean.Lote#232]
        at auge.conexao.OrdemItensService.getOrdemItensRotaList(OrdemItensService.java:229)
        at auge.action.ListaOrdemItensRotaAction.execute(ListaOrdemItensRotaAction.java:65)
        at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)


I do know it happens because it tried to fetch an ID that doesn't exist. But the thing it that I needed it to ignore it instead of giving me an error.

My HQL is:

Code:
                    Query select = session.createQuery("from OrdemItens o where" +
                            " o.ordemDeProducao.status <> 1 " +                           
                            " order by o.lote, " +
                            " o.ordemDeProducao.numeroOrdem, " +
                            " o.numeroOrdemItens");


In the "order by o.lote" is that it's finding this error. The thing is that I'm working on an already existing database and I know that i WILL find this error. I wanted to find a way to ignore it, 'cause I can't fix it.

Is there a way? Or this will stop me from using hibernate?

_________________
Don't forget to rate if the post helped!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 3:22 pm 
Newbie

Joined: Mon Oct 24, 2005 9:16 am
Posts: 7
Why don't you send the result set to a list and check if the list is empty?

List lst = sesion.query("....").list();
if (lst.isEmpty()) ...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 3:26 pm 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
The thing is that the list is NOT empty. It does return me results, after all I'm selecting another object.

The object I'm selecting has a many-to-one relation with the object that is not present in the DB. That is, in my OrdemItens object (that is being selected) there's a property Lote (which is the one that's missing in some rows). In my OrdemItens table there's a field for the Lote pk.

All I wanna do is select OrdemItens and ignore if the relation is invalid.

Thanks.

_________________
Don't forget to rate if the post helped!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 3:38 pm 
Newbie

Joined: Mon Oct 24, 2005 9:16 am
Posts: 7
I would remove te "order by" in the query and use a filter instead.
Look in the documentation about how to create a filter on a persistent object .


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 3:40 pm 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
When you say using a filter, you mean criteria?
Will it fix my problem?

_________________
Don't forget to rate if the post helped!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 3:53 pm 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
Isn't there some magic mapping option like "ignore-not-found=true" or something?

_________________
Don't forget to rate if the post helped!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 4:01 pm 
Newbie

Joined: Mon Oct 24, 2005 9:16 am
Posts: 7
a filter can be applied to a persistent
collection (or array). It’s commonly used to further restrict or order a result.

use it on an already loaded Item and its collection. For example:
List results = session.createFilter( item.getBids(),
"order by this.amount asc" )
.list();

This is a concept different from criteria query you refer to.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 4:23 pm 
Regular
Regular

Joined: Thu Apr 14, 2005 2:15 pm
Posts: 66
Remove the order by from the query. After get the list, you can sort the list using Collections.sort().


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 5:51 pm 
Beginner
Beginner

Joined: Tue Apr 05, 2005 4:27 pm
Posts: 40
Location: canada
there is a not-found="ignore" option that might be of use. personally i've never used it.

http://www.hibernate.org/hib_docs/v3/reference/en/html/mapping.html#mapping-declaration-manytoone


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 6:19 am 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
Thank you everyone.

I'll remove the order by and sort the collection later, and I'll also use the not-found="ignore" to guarantee

:)

_________________
Don't forget to rate if the post helped!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 7:32 am 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
Now I have the following HQL:

Code:
Query select = session.createQuery("from OrdemItens o where o.ordemDeProducao.status <> 1 ");


and my mapping for this association is:
Code:
       <many-to-one name="lote" column="lote" class="auge.bean.Lote"
                    not-null="false" lazy="false" not-found="ignore"/>   


Without the not-found="ignore", it gives me the same "No row with the given identifier exists" error. With it, it gives me no error and returns a list - but this list ignores the rows where there's no association (which is, where the field is null). All I want now is to get thiis rows too. Anyone has any idea?

_________________
Don't forget to rate if the post helped!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 8:09 am 
Regular
Regular

Joined: Thu Apr 14, 2005 2:15 pm
Posts: 66
This behavier is strange for me, because the documentations says that the behavier for not-found="ignore" is:

not-found (optional - defaults to exception): Specifies how foreign keys that reference missing rows will be handled: ignore will treat a missing row as a null association.

Try this for a test and check if the objects are returning.
session.createQuery("from OrdemItens");


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