开发者

How to create a custom finder using spring roo

I have an entity Upgrade which has a set of Product objects. I want a finder object like findProductsByUpgrade_Name(String name), but I think开发者_如何学Python I need to create this myself as I can't find out how to do this. Can anyone give me any pointers or point me in the right direction?

Upgrade:

package com.company.pr.domain;

import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;
import org.springframework.roo.addon.entity.RooEntity;
import com.company.pr.domain.UpgradeType;
import javax.persistence.ManyToOne;
import java.util.Set;
import com.company.pr.domain.Product;
import java.util.HashSet;
import javax.persistence.ManyToMany;
import javax.persistence.CascadeType;

@RooJavaBean
@RooToString
@RooEntity
public class Upgrade {

    private String name;

    @ManyToOne
    private UpgradeType upgrade_type;

    @ManyToMany(cascade = CascadeType.ALL)
    private Set<Product> products = new HashSet<Product>();

    private String description;
}

Product:

package com.company.pr.domain;

import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;
import org.springframework.roo.addon.entity.RooEntity;
import com.company.pr.domain.PackageType;
import javax.persistence.ManyToOne;

@RooJavaBean
@RooToString
@RooEntity
public class Product {

    private String product_id;

    private String product_name;

    private String ca_product;

    @ManyToOne
    private PackageType packageType;

    private String description;
}


Not sure if ROO could generate such a finder for you - if you have not tried the finder list command thats the way to go.

If you need to create your own HQL/JPQL etc then you should follow the recommended pattern for that, see Roo - add custom finder

Hope that helps you a little step ahead.


You need the other direction of your realtion:

@ManyToMany(cascade = CascadeType.ALL, mappedBy = "products")
private Set<Upgrade> upgradets = new HashSet<Upgrade>();

then you can make the finder finder add findProduckByUpgrades

HF

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜