Announcement Announcement Module
Collapse
No announcement yet.
problems jpa query of spring roo Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • problems jpa query of spring roo

    Code:
    120725 16:37:41  2520 Query     SELECT 1
                     2520 Query     select bidlicense0_.Idx as Idx4_, bidlicense0_.BidIdx as BidIdx4_, bidlicense0_.LicenseCode as LicenseC2_4_, bidlicense0_.LicenseGroup as LicenseG3_4_, bidlicense0_.LicenseName as LicenseN4_4_ from BidLicense bidlicense0_ where bidlicense0_.BidIdx=1560
                     2520 Query     SELECT 1
                     2520 Query     SELECT 1
                     2520 Query     select bid0_.Idx as Idx1_1_, bid0_.BasicAmount as BasicAmo2_1_1_, bid0_.BidGroup as BidGroup1_1_, bid0_.BidNo as BidNo1_1_, bid0_.BidRepeat as BidRepeat1_1_, bid0_.BidStyle as BidStyle1_1_, bid0_.BidTitle as BidTitle1_1_, bid0_.BidType as BidType1_1_, crawlingsi1_.Name as Name5_0_, crawlingsi1_.Url as Url5_0_ from Bid bid0_ inner join CrawlingSite crawlingsi1_ on bid0_.CrawlingSiteIdx=crawlingsi1_.Idx where bid0_.Idx=1560





    see below my code
    com.test.roo.domain.BidLicense
    Code:
    mport org.springframework.roo.addon.json.RooJson;
    import org.springframework.roo.addon.tostring.RooToString;
    
    @RooJavaBean
    @RooToString
    @RooDbManaged(automaticallyDelete = true)
    @RooJson
    @RooJpaActiveRecord(versionField = "", table = "BidLicense")
    public class BidLicense {
    
        public static List<com.test.roo.domain.BidLicense> findBidLicensesByBidIdx(int bidIdx) {
            CriteriaBuilder cb = BidLicense.entityManager().getCriteriaBuilder();
            CriteriaQuery<BidLicense> cq = cb.createQuery(BidLicense.class);
            Root<BidLicense> tableBL = cq.from(BidLicense.class);
            cq.select(tableBL).where(cb.equal(tableBL.get("bidIdx"), bidIdx));
            return entityManager().createQuery(cq).getResultList();
        }
    }


    and
    com.test.roo.web.BidLicenseController
    Code:
    import org.springframework.http.HttpHeaders;
    .
    .
    .
    .
    
    
    @RooWebJson(jsonObject = BidLicense.class)
    @Controller
    @RequestMapping("/bidlicenses")
    public class BidLicenseController
    {
    @RequestMapping(value = "/{idx}", headers = "Accept=application/json")
        @ResponseBody
        public ResponseEntity<String> showJson(@PathVariable("idx") Integer idx)
        {
    		List<BidLicense> listBL  = BidLicense.findBidLicensesByBidIdx(idx);
    		
            HttpHeaders headers = new HttpHeaders();
            
            headers.add("Content-Type", "application/json; charset=utf-8");
            if (listBL == null)
            {
                return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
            }
            
            String serializer	= new JSONSerializer().rootName("license").serialize(listBL);
            
            return new ResponseEntity<String>(serializer, headers, HttpStatus.OK);
        }
    }
    [CODE]

    ASPECTJ

    Code:
    package com.test.roo.domain;
    
    import javax.persistence.Column;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.validation.constraints.NotNull;
    import com.test.roo.domain.Bid;
    import com.test.roo.domain.BidLicense;
    
    privileged aspect BidLicense_Roo_DbManaged {
        
        @ManyToOne
        @JoinColumn(name = "BidIdx", referencedColumnName = "Idx", nullable = false)
        private Bid BidLicense.bidIdx;
        
        @Column(name = "LicenseCode", length = 20)
        @NotNull
        private String BidLicense.licenseCode;
        
        @Column(name = "LicenseName", length = 20)
        @NotNull
        private String BidLicense.licenseName;
        
        @Column(name = "LicenseGroup")
        @NotNull
        private Character BidLicense.licenseGroup;
        
        public Bid BidLicense.getBidIdx() {
            return bidIdx;
        }
        
        public void BidLicense.setBidIdx(Bid bidIdx) {
            this.bidIdx = bidIdx;
        }
        
        public String BidLicense.getLicenseCode() {
            return licenseCode;
        }
        
        public void BidLicense.setLicenseCode(String licenseCode) {
            this.licenseCode = licenseCode;
        }
     .
    .
    .
    .



    i wanna only one query


    Code:
                   2520 Query     select bidlicense0_.Idx as Idx4_, bidlicense0_.BidIdx as BidIdx4_, bidlicense0_.LicenseCode as LicenseC2_4_, bidlicense0_.LicenseGroup as LicenseG3_4_, bidlicense0_.LicenseName as LicenseN4_4_ from BidLicense bidlicense0_ where bidlicense0_.BidIdx=1560
    But

    I think the this query is a waste of resource.

    Code:
    120725 16:37:41  2520 Query     SELECT 1
                     2520 Query     select bidlicense0_.Idx as Idx4_, bidlicense0_.BidIdx as BidIdx4_, bidlicense0_.LicenseCode as LicenseC2_4_, bidlicense0_.LicenseGroup as LicenseG3_4_, bidlicense0_.LicenseName as LicenseN4_4_ from BidLicense bidlicense0_ where bidlicense0_.BidIdx=1560
                     2520 Query     SELECT 1
                     2520 Query     SELECT 1
                     2520 Query     select bid0_.Idx as Idx1_1_, bid0_.BasicAmount as BasicAmo2_1_1_, bid0_.BidGroup as BidGroup1_1_, bid0_.BidNo as BidNo1_1_, bid0_.BidRepeat as BidRepeat1_1_, bid0_.BidStyle as BidStyle1_1_, bid0_.BidTitle as BidTitle1_1_, bid0_.BidType as BidType1_1_, crawlingsi1_.Name as Name5_0_, crawlingsi1_.Url as Url5_0_ from Bid bid0_ inner join CrawlingSite crawlingsi1_ on bid0_.CrawlingSiteIdx=crawlingsi1_.Idx where bid0_.Idx=1560

    What should I do to solve this problem?

    Who is able to do this problem?
    Last edited by racingslab; Jul 25th, 2012, 05:35 AM. Reason: problems jpa query of spring roo(헬미~ :(
Working...
X