2011-12-05 3 views
0

私は幸せなWebサービスをnetbeansで作成します。私はデータベースとnetbeansを指定してすべてを作成します。 、これは生成されたコードである生成された穏やかなWebサービスでより多くのクエリを取得

converter.city (http://localhost:8080/Data/resources/converter.city) 

converter.city/{id}(http://localhost:8080/Data/resources/converter.city/{id}) 

converter.city/{from}/{to(http://localhost:8080/Data/resources/converter.city/{from}/{to}) 

converter.city/count(http://localhost:8080/Data/resources/converter.city/count) 

生成されたコードがある私に興味の多くのクエリとその中の一つの最初の部分を見て

@Entity 
@Table(name = "City") 
@XmlRootElement 
@NamedQueries({ 
    @NamedQuery(name = "City.findAll", query = "SELECT c FROM City c"), 
    @NamedQuery(name = "City.findById", query = "SELECT c FROM City c WHERE c.id = :id"), 
    @NamedQuery(name = "City.findByName", query = "SELECT c FROM City c WHERE c.name = :name"), 
    @NamedQuery(name = "City.findByCountryCode", query = "SELECT c FROM City c WHERE c.countryCode = :countryCode"), 
    @NamedQuery(name = "City.findByDistrict", query = "SELECT c FROM City c WHERE c.district = :district"), 
    @NamedQuery(name = "City.findByPopulation", query = "SELECT c FROM City c WHERE c.population = :population")}) 
public class City implements Serializable { 
    private static final long serialVersionUID = 1L; 
    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    @Basic(optional = false) 
    @NotNull 
    @Column(name = "ID") 
    private Integer id; 
    @Basic(optional = false) 
    @NotNull 
    @Size(min = 1, max = 35) 
    @Column(name = "Name") 
    private String name; 
    @Basic(optional = false) 
    @NotNull 
    @Size(min = 1, max = 3) 
    @Column(name = "CountryCode") 
    private String countryCode; 
    @Basic(optional = false) 
    @NotNull 
    @Size(min = 1, max = 20) 
    @Column(name = "District") 
    private String district; 
    @Basic(optional = false) 
    @NotNull 
    @Column(name = "Population") 
    private int population; 

    public City() { 
    } 

    public City(Integer id) { 
     this.id = id; 
    } 

    public City(Integer id, String name, String countryCode, String district, int population) { 
     this.id = id; 
     this.name = name; 
     this.countryCode = countryCode; 
     this.district = district; 
     this.population = population; 
    } 

    public Integer getId() { 
     return id; 
    } 

    public void setId(Integer id) { 
     this.id = id; 
    } 

    public String getName() { 
     return name; 
    } 

    public void setName(String name) { 
     this.name = name; 
    } 

    public String getCountryCode() { 
     return countryCode; 
    } 

    public void setCountryCode(String countryCode) { 
     this.countryCode = countryCode; 
    } 

    public String getDistrict() { 
     return district; 
    } 

    public void setDistrict(String district) { 
     this.district = district; 
    } 

    public int getPopulation() { 
     return population; 
    } 

    public void setPopulation(int population) { 
     this.population = population; 
    } 

    @Override 
    public int hashCode() { 
     int hash = 0; 
     hash += (id != null ? id.hashCode() : 0); 
     return hash; 
    } 

    @Override 
    public boolean equals(Object object) { 
     // TODO: Warning - this method won't work in the case the id fields are not set 
     if (!(object instanceof City)) { 
      return false; 
     } 
     City other = (City) object; 
     if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { 
      return false; 
     } 
     return true; 
    } 

    @Override 
    public String toString() { 
     return "converter.City[ id=" + id + " ]"; 
    } 

:サブリソースでは、私は唯一の4 URIを持っています

@NamedQuery(name = "City.findByCountryCode", query = "SELECT c FROM City c WHERE c.countryCode = :countryCode")  

City.findByCountryCodeはどのように使用できますか?

答えて

1
Query query = em.createNamedQuery("City.findByCountryCode") 
    .setParameter("countryCode", yourCountryCode); 
関連する問題