我有一个实体升级,它有一组Product对象。我想要一个像findProductsByUpgrade_Name(String name)这样的finder对象,但我想我需要自己创建,因为我无法找到如何做到这一点。任何人都可以给我任何指示或指出我正确的方向吗?
升级:
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;
}
产品:
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;
}
答案 0 :(得分:2)
不确定ROO是否可以为您生成这样的查找程序 - 如果您还没有尝试过查找程序列表命令。
如果您需要创建自己的HQL / JPQL等,那么您应该遵循建议的模式,请参阅Roo - add custom finder
希望能帮助你领先一步。
答案 1 :(得分:2)
你需要另一个方向:
@ManyToMany(cascade = CascadeType.ALL, mappedBy = "products")
private Set<Upgrade> upgradets = new HashSet<Upgrade>();
然后你可以让finder finder添加findProduckByUpgrades
HF