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.  [ 1 post ] 
Author Message
 Post subject: The most strange bug I ever have with Hibernate in 2 years
PostPosted: Sun Jul 22, 2007 11:00 pm 
Newbie

Joined: Sun Jul 22, 2007 8:38 pm
Posts: 1
Hi,
I have a very strange bug with Hibernate, maybe an expert could please tell me what kind of problem it is:

I have this method, this query only work a couple of first times with my tester, then It only returns one object in the list (supposed to return many)


Code:
public List<ReservedNumber> findReservedNumber(Long minReservedNumber, Long maxReservedNumber, String publicationTypeConstantId) {
     
        PublicationTypeConstant publicationTypeConstant = publicationTypeConstants
        .getConstantByName(publicationTypeConstantId);
     
        DetachedCriteria criteria = DetachedCriteria
        .forClass(ReservedNumber.class).add(
                Expression.and(Expression.between("reservedNumber", minReservedNumber, maxReservedNumber), Expression.eq("publicationTypeConstant", publicationTypeConstant)));
        List<ReservedNumber> reservedNumberList = reservedNumberDao.findByCriteria(criteria);
        return reservedNumberList;
     
    }



if I change it to this, still the same:



Code:
public List<ReservedNumber> findReservedNumber(Long minReservedNumber, Long maxReservedNumber, String publicationTypeConstantId) {
      String queryString = "from ReservedNumber rn where rn.publicationTypeConstant = :publicationTypeConstant and (rn.reservedNumber >= :minReservedNumber and rn.reservedNumber <= :maxReservedNumber)";
        String paramNames[] = new String[] { "publicationTypeConstant",
                "minReservedNumber", "maxReservedNumber" };
        Object values[] = new Object[] { publicationTypeConstant,
                minReservedNumber, maxReservedNumber };
        List<ReservedNumber> reservedNumberList = reservedNumberDao
                .findByNamedParam(queryString, paramNames, values);       
        return reservedNumberList;       
       
    }


In Hibernate log, can get this prepareStatement
select this_.id as id44_11_, this_.reserved_number as reserved2_44_11_, this_.reserved as reserved44_11_, this_.used as used44_11_, this_.committee_id as committee5_44_11_, this_.publication_type_id as publicat6_44_11_, publicatio2_.id as id35_0_, publicatio2_.active as active35_0_, publicatio2_.default_selection as default4_35_0_, publicatio2_.description as descript5_35_0_, publicatio2_.sort_sequence as sort6_35_0_, publicatio2_.show_in_ui as show7_35_0_, publicatio3_.id as id40_1_, publicatio3_.publication_type_id as publicat3_40_1_, publicatio3_.base_number as base2_40_1_, publicatio3_.reserved_number_id as reserved4_40_1_, publicatio4_.id as id35_2_, publicatio4_.active as active35_2_, publicatio4_.default_selection as default4_35_2_, publicatio4_.description as descript5_35_2_, publicatio4_.sort_sequence as sort6_35_2_, publicatio4_.show_in_ui as show7_35_2_, standards5_.collection_id as collection29_13_, standards5_.id as id13_, standards5_.id as id41_3_, standards5_.last_updated as last3_41_3_, standards5_.version as version41_3_, standards5_.project_id as project26_41_3_, standards5_.publication_number as publicat5_41_3_, standards5_.title as title41_3_, standards5_.index_number as index7_41_3_, standards5_.objective as objective41_3_, standards5_.history as history41_3_, standards5_.number_of_pages as number10_41_3_, standards5_.recommended_retail_price as recomme11_41_3_, standards5_.isbn as isbn41_3_, standards5_.publication_date as publica13_41_3_, standards5_.webshop_link as webshop14_41_3_, standards5_.treasury_parents as treasury15_41_3_, standards5_.treasury_supersedes as treasury16_41_3_, standards5_.treasury_abstract as treasury17_41_3_, standards5_.treasury_status as treasury18_41_3_, standards5_.treasury_scope as treasury19_41_3_, standards5_.document_type as document27_41_3_, standards5_.publication_status as publica28_41_3_, standards5_.publication_usage as publica20_41_3_, standards5_.publication_priority as publica21_41_3_, standards5_.interim as interim41_3_, standards5_.joint as joint41_3_, standards5_.joint_reason as joint24_41_3_, standards5_.collection_id as collection29_41_3_, standards5_.part_numbers as part25_41_3_, standards5_.publication_type as publicat1_41_3_, project6_.id as id38_4_, project6_.drafting_leader as drafting2_38_4_, project6_.is_highlighted as is3_38_4_, project6_.committee_id as committee4_38_4_, project6_.project_manager_id as project5_38_4_, project6_.orig_draft_target_date as orig6_38_4_, project6_.estimate_draft_target_date as estimate7_38_4_, project6_.committee_approval_date as committee8_38_4_, project6_.created_date as created9_38_4_, project6_.workspace_id as workspace10_38_4_, documentty7_.id as id35_5_, documentty7_.active as active35_5_, documentty7_.default_selection as default4_35_5_, documentty7_.description as descript5_35_5_, documentty7_.sort_sequence as sort6_35_5_, documentty7_.show_in_ui as show7_35_5_, publicatio8_.id as id35_6_, publicatio8_.active as active35_6_, publicatio8_.default_selection as default4_35_6_, publicatio8_.description as descript5_35_6_, publicatio8_.sort_sequence as sort6_35_6_, publicatio8_.show_in_ui as show7_35_6_, internatio9_.id as id42_7_, internatio9_.collection_id as collection4_42_7_, internatio9_.reference_number as reference2_42_7_, internatio9_.publication_relationship as publicat3_42_7_, internatio9_.organization_id as organiza5_42_7_, organizati10_.id as id34_8_, organizati10_.abbreviation as abbrevia2_34_8_, organizati10_.name as name34_8_, organizati10_.international as internat4_34_8_, localorgan11_.id as id43_9_, localorgan11_.collection_id as collection3_43_9_, localorgan11_.reference_number as reference2_43_9_, localorgan11_.organization_id as organiza4_43_9_, organizati12_.id as id34_10_, organizati12_.abbreviation as abbrevia2_34_10_, organizati12_.name as name34_10_, organizati12_.international as internat4_34_10_ from tnguyen.reserved_number this_ left outer join tnguyen.system_constant publicatio2_ on this_.publication_type_id=publicatio2_.id left outer join tnguyen.publication_collection publicatio3_ on this_.id=publicatio3_.reserved_number_id left outer join tnguyen.system_constant publicatio4_ on publicatio3_.publication_type_id=publicatio4_.id left outer join tnguyen.publication standards5_ on publicatio3_.id=standards5_.collection_id left outer join tnguyen.project project6_ on standards5_.project_id=project6_.id left outer join tnguyen.system_constant documentty7_ on standards5_.document_type=documentty7_.id left outer join tnguyen.system_constant publicatio8_ on standards5_.publication_status=publicatio8_.id left outer join tnguyen.international_organisation internatio9_ on publicatio3_.id=internatio9_.collection_id left outer join tnguyen.organization organizati10_ on internatio9_.organization_id=organizati10_.id left outer join tnguyen.local_organisation localorgan11_ on publicatio3_.id=localorgan11_.collection_id left outer join tnguyen.organization organizati12_ on localorgan11_.organization_id=organizati12_.id where (this_.reserved_number between ? and ?and this_.publication_type_id=?)

If I put the parameter value in the "?", it returned me the right result


But if I change to this, it works for now:


Code:
public List<ReservedNumber> findReservedNumber(Long minReservedNumber, Long maxReservedNumber, String publicationTypeConstantId) {
               
        String queryString = "from ReservedNumber rn where rn.publicationTypeConstant.id ='"
                + publicationTypeConstantId
                + "' and (rn.reservedNumber >= "
                + minReservedNumber
                + " and rn.reservedNumber <= "
                + maxReservedNumber + ")";

        List<ReservedNumber> reservedNumberList = reservedNumberDao.find(queryString);
       
        return reservedNumberList;       
       
    }


The database is Oracle 10g, I think it's is something to do with the preparedstatement hibernate catching.


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

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.