开发者

Problem while retrieving Object using HQL

I am new to hibernate and trying to learnits nuts and bolts.i have a table Destination which has destinationid as unique Key i also have UUID as unique key in the destination table. i want to provide a method by which user can fetch Destination based on destinationid also so i tried to use HQL as below

Session session=getSessionFactory().getCurrentSession();
        Destination destination=null;
        String queryString="from Destination destination "+
                            "where destination.destinationID = :destinationid";
        Query query= session.createQuery(queryString).setParameter("destinationid", destinationId, Hibernate.STRING);
        @SuppressWarnings("unchecked")
        List<Destination> list=qu

ery.list();

my Destination class has refrence of many other subclasses as collection all of which has been defined as lazy load

<set name="roadTransport" table="ROADTRANSPORT" inverse="true" lazy="true" cascade="save-update">

there are around 9-10 classes whcih are being refred from inside Desttination class all being lazily loaded.

I am importing destination xml and this xmlis being provided by some third part system so there is no way i can associate UUID and i need to decide if import is to be done in update mode or for new destination.so destinationid is the only 开发者_StackOverflowway i can find to check if the destination is already in the DB or not.

my problem is for new destination the above HQL query is working fine and new destination is being imported in to the DB but for the existing it seems that its not working as expected and Query seems to be in hanged state

        Hibernate: 
            /* 
        from
            Destination destination 
        where
            destination.destinationID = :destinationid */ select
                destinatio0_.UUID as UUID0_,
                destinatio0_.DESTINATIONID as DESTINAT2_0_,
                destinatio0_.NAME as NAME0_,
                destinatio0_.SHORTDESCRIPTION as SHORTDES4_0_,
                destinatio0_.LONGDESCRIPTION as LONGDESC5_0_,
                destinatio0_.IMAGE as IMAGE0_,
                destinatio0_.GALLERYPATH as GALLERYP7_0_,
                destinatio0_.RATING as RATING0_,
                destinatio0_.LASTMODIFIED as LASTMODI9_0_,
                destinatio0_.CREATIONDATE as CREATIO10_0_,
                destinatio0_.STATEID as STATEID0_,
                destinatio0_.TYPECODE as TYPECODE0_,
                destinatio0_.COUNTRYCODE as COUNTRY13_0_,
                destinatio0_.POPULARITY as POPULARITY0_ 
            from
                travellingrants.DESTINATION destinatio0_ 
            where
                destinatio0_.DESTINATIONID=?
        Hibernate: 
            /* load com.raisonne.tr.model.destination.destinationattributes.Culture */ select
                culture0_.UUID as UUID4_2_,
                culture0_.SHORTDESCRIPTION as SHORTDES2_4_2_,
                culture0_.LONGDESCRIPTION as LONGDESC3_4_2_,
                culture0_.CREATIONDATE as CREATION4_4_2_,
                culture0_.LASTMODIFIED as LASTMODI5_4_2_,
                destinatio1_.UUID as UUID0_0_,
                destinatio1_.DESTINATIONID as DESTINAT2_0_0_,
                destinatio1_.NAME as NAME0_0_,
                destinatio1_.SHORTDESCRIPTION as SHORTDES4_0_0_,
                destinatio1_.LONGDESCRIPTION as LONGDESC5_0_0_,
                destinatio1_.IMAGE as IMAGE0_0_,
                destinatio1_.GALLERYPATH as GALLERYP7_0_0_,
                destinatio1_.RATING as RATING0_0_,
                destinatio1_.LASTMODIFIED as LASTMODI9_0_0_,
                destinatio1_.CREATIONDATE as CREATIO10_0_0_,
                destinatio1_.STATEID as STATEID0_0_,
                destinatio1_.TYPECODE as TYPECODE0_0_,
                destinatio1_.COUNTRYCODE as COUNTRY13_0_0_,
                destinatio1_.POPULARITY as POPULARITY0_0_,
                culture2_.UUID as UUID4_1_,
                culture2_.SHORTDESCRIPTION as SHORTDES2_4_1_,
                culture2_.LONGDESCRIPTION as LONGDESC3_4_1_,
                culture2_.CREATIONDATE as CREATION4_4_1_,
                culture2_.LASTMODIFIED as LASTMODI5_4_1_ 
            from
                travellingrants.CULTURE culture0_ 
            left outer join
                travellingrants.DESTINATION destinatio1_ 
                    on culture0_.UUID=destinatio1_.UUID 
            left outer join
                travellingrants.CULTURE culture2_ 



     on destinatio1_.UUID=culture2_.UUID 
where
    culture0_.UUID=?

i am new to hibernate but after seeing the query generated by hibernate for the already existing destination,it seems it is facing some kind of cyclic refrences but i am not sure how to avoid this or is there any better way to check for an already existing entity based on the unique key (not primary key)

Thanks in advance


use this options inverse="false" lazy="false" fetch="join". The problem is with lazy=true.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜