论坛首页 入门技术论坛

Hibernate的视图查询-求解

浏览 2885 次
该帖已经被评为新手帖
作者 正文
   发表时间:2007-09-19  

package com.longge.vo;

/**
 * Productview generated by MyEclipse Persistence Tools
 */

public class Productview implements java.io.Serializable {

 // Fields

 private ProductviewId id;

 // Constructors

 /** default constructor */
 public Productview() {
 }

 /** full constructor */
 public Productview(ProductviewId id) {
  this.id = id;
 }

 // Property accessors

 public ProductviewId getId() {
  return this.id;
 }

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

}

package com.longge.vo;

import java.util.Date;

/**
 * ProductviewId generated by MyEclipse Persistence Tools
 */

public class ProductviewId implements java.io.Serializable {

 // Fields

 private Integer id;

 private String username;

 private Integer genre;

 private String name;

 private String title;

 private Integer category;

 private Integer validity;

 private String unit;

 private String price;

 private String revise;

 private String gross;

 private String deadline;

 private String explain;

 private String imgurl;

 private Integer condition;

 private Date times;

 private Integer retainday;

 private String report;

 private Integer state;

 // Constructors

 /** default constructor */
 public ProductviewId() {
 }

 /** minimal constructor */
 public ProductviewId(Integer id, String username, Integer genre,
   String name, String title, Integer category) {
  this.id = id;
  this.username = username;
  this.genre = genre;
  this.name = name;
  this.title = title;
  this.category = category;
 }

 /** full constructor */
 public ProductviewId(Integer id, String username, Integer genre,
   String name, String title, Integer category, Integer validity,
   String unit, String price, String revise, String gross,
   String deadline, String explain, String imgurl, Integer condition,
   Date times, Integer retainday, String report, Integer state) {
  this.id = id;
  this.username = username;
  this.genre = genre;
  this.name = name;
  this.title = title;
  this.category = category;
  this.validity = validity;
  this.unit = unit;
  this.price = price;
  this.revise = revise;
  this.gross = gross;
  this.deadline = deadline;
  this.explain = explain;
  this.imgurl = imgurl;
  this.condition = condition;
  this.times = times;
  this.retainday = retainday;
  this.report = report;
  this.state = state;
 }

 // Property accessors

 public Integer getId() {
  return this.id;
 }

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

 public String getUsername() {
  return this.username;
 }

 public void setUsername(String username) {
  this.username = username;
 }

 public Integer getGenre() {
  return this.genre;
 }

 public void setGenre(Integer genre) {
  this.genre = genre;
 }

 public String getName() {
  return this.name;
 }

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

 public String getTitle() {
  return this.title;
 }

 public void setTitle(String title) {
  this.title = title;
 }

 public Integer getCategory() {
  return this.category;
 }

 public void setCategory(Integer category) {
  this.category = category;
 }

 public Integer getValidity() {
  return this.validity;
 }

 public void setValidity(Integer validity) {
  this.validity = validity;
 }

 public String getUnit() {
  return this.unit;
 }

 public void setUnit(String unit) {
  this.unit = unit;
 }

 public String getPrice() {
  return this.price;
 }

 public void setPrice(String price) {
  this.price = price;
 }

 public String getRevise() {
  return this.revise;
 }

 public void setRevise(String revise) {
  this.revise = revise;
 }

 public String getGross() {
  return this.gross;
 }

 public void setGross(String gross) {
  this.gross = gross;
 }

 public String getDeadline() {
  return this.deadline;
 }

 public void setDeadline(String deadline) {
  this.deadline = deadline;
 }

 public String getExplain() {
  return this.explain;
 }

 public void setExplain(String explain) {
  this.explain = explain;
 }

 public String getImgurl() {
  return this.imgurl;
 }

 public void setImgurl(String imgurl) {
  this.imgurl = imgurl;
 }

 public Integer getCondition() {
  return this.condition;
 }

 public void setCondition(Integer condition) {
  this.condition = condition;
 }

 public Date getTimes() {
  return this.times;
 }

 public void setTimes(Date times) {
  this.times = times;
 }

 public Integer getRetainday() {
  return this.retainday;
 }

 public void setRetainday(Integer retainday) {
  this.retainday = retainday;
 }

 public String getReport() {
  return this.report;
 }

 public void setReport(String report) {
  this.report = report;
 }

 public Integer getState() {
  return this.state;
 }

 public void setState(Integer state) {
  this.state = state;
 }

 public boolean equals(Object other) {
  if ((this == other))
   return true;
  if ((other == null))
   return false;
  if (!(other instanceof ProductviewId))
   return false;
  ProductviewId castOther = (ProductviewId) other;

  return ((this.getId() == castOther.getId()) || (this.getId() != null
    && castOther.getId() != null && this.getId().equals(
    castOther.getId())))
    && ((this.getUsername() == castOther.getUsername()) || (this
      .getUsername() != null
      && castOther.getUsername() != null && this
      .getUsername().equals(castOther.getUsername())))
    && ((this.getGenre() == castOther.getGenre()) || (this
      .getGenre() != null
      && castOther.getGenre() != null && this.getGenre()
      .equals(castOther.getGenre())))
    && ((this.getName() == castOther.getName()) || (this.getName() != null
      && castOther.getName() != null && this.getName()
      .equals(castOther.getName())))
    && ((this.getTitle() == castOther.getTitle()) || (this
      .getTitle() != null
      && castOther.getTitle() != null && this.getTitle()
      .equals(castOther.getTitle())))
    && ((this.getCategory() == castOther.getCategory()) || (this
      .getCategory() != null
      && castOther.getCategory() != null && this
      .getCategory().equals(castOther.getCategory())))
    && ((this.getValidity() == castOther.getValidity()) || (this
      .getValidity() != null
      && castOther.getValidity() != null && this
      .getValidity().equals(castOther.getValidity())))
    && ((this.getUnit() == castOther.getUnit()) || (this.getUnit() != null
      && castOther.getUnit() != null && this.getUnit()
      .equals(castOther.getUnit())))
    && ((this.getPrice() == castOther.getPrice()) || (this
      .getPrice() != null
      && castOther.getPrice() != null && this.getPrice()
      .equals(castOther.getPrice())))
    && ((this.getRevise() == castOther.getRevise()) || (this
      .getRevise() != null
      && castOther.getRevise() != null && this.getRevise()
      .equals(castOther.getRevise())))
    && ((this.getGross() == castOther.getGross()) || (this
      .getGross() != null
      && castOther.getGross() != null && this.getGross()
      .equals(castOther.getGross())))
    && ((this.getDeadline() == castOther.getDeadline()) || (this
      .getDeadline() != null
      && castOther.getDeadline() != null && this
      .getDeadline().equals(castOther.getDeadline())))
    && ((this.getExplain() == castOther.getExplain()) || (this
      .getExplain() != null
      && castOther.getExplain() != null && this.getExplain()
      .equals(castOther.getExplain())))
    && ((this.getImgurl() == castOther.getImgurl()) || (this
      .getImgurl() != null
      && castOther.getImgurl() != null && this.getImgurl()
      .equals(castOther.getImgurl())))
    && ((this.getCondition() == castOther.getCondition()) || (this
      .getCondition() != null
      && castOther.getCondition() != null && this
      .getCondition().equals(castOther.getCondition())))
    && ((this.getTimes() == castOther.getTimes()) || (this
      .getTimes() != null
      && castOther.getTimes() != null && this.getTimes()
      .equals(castOther.getTimes())))
    && ((this.getRetainday() == castOther.getRetainday()) || (this
      .getRetainday() != null
      && castOther.getRetainday() != null && this
      .getRetainday().equals(castOther.getRetainday())))
    && ((this.getReport() == castOther.getReport()) || (this
      .getReport() != null
      && castOther.getReport() != null && this.getReport()
      .equals(castOther.getReport())))
    && ((this.getState() == castOther.getState()) || (this
      .getState() != null
      && castOther.getState() != null && this.getState()
      .equals(castOther.getState())));
 }

 public int hashCode() {
  int result = 17;

  result = 37 * result + (getId() == null ? 0 : this.getId().hashCode());
  result = 37 * result
    + (getUsername() == null ? 0 : this.getUsername().hashCode());
  result = 37 * result
    + (getGenre() == null ? 0 : this.getGenre().hashCode());
  result = 37 * result
    + (getName() == null ? 0 : this.getName().hashCode());
  result = 37 * result
    + (getTitle() == null ? 0 : this.getTitle().hashCode());
  result = 37 * result
    + (getCategory() == null ? 0 : this.getCategory().hashCode());
  result = 37 * result
    + (getValidity() == null ? 0 : this.getValidity().hashCode());
  result = 37 * result
    + (getUnit() == null ? 0 : this.getUnit().hashCode());
  result = 37 * result
    + (getPrice() == null ? 0 : this.getPrice().hashCode());
  result = 37 * result
    + (getRevise() == null ? 0 : this.getRevise().hashCode());
  result = 37 * result
    + (getGross() == null ? 0 : this.getGross().hashCode());
  result = 37 * result
    + (getDeadline() == null ? 0 : this.getDeadline().hashCode());
  result = 37 * result
    + (getExplain() == null ? 0 : this.getExplain().hashCode());
  result = 37 * result
    + (getImgurl() == null ? 0 : this.getImgurl().hashCode());
  result = 37 * result
    + (getCondition() == null ? 0 : this.getCondition().hashCode());
  result = 37 * result
    + (getTimes() == null ? 0 : this.getTimes().hashCode());
  result = 37 * result
    + (getRetainday() == null ? 0 : this.getRetainday().hashCode());
  result = 37 * result
    + (getReport() == null ? 0 : this.getReport().hashCode());
  result = 37 * result
    + (getState() == null ? 0 : this.getState().hashCode());
  return result;
 }

}
<!----><class catalog="machine" table="productview" schema="dbo" name="com.longge.vo.Productview"></class>

<hibernate-mapping>
    <class name="com.longge.vo.Productview" table="productview" schema="dbo" catalog="machine">
        <composite-id name="id" class="com.longge.vo.ProductviewId">
            <key-property name="id" type="integer">
                <column name="id" />
            </key-property>
            <key-property name="username" type="string">
                <column name="username" length="20" />
            </key-property>
            <key-property name="genre" type="integer">
                <column name="genre" />
            </key-property>
            <key-property name="name" type="string">
                <column name="name" length="50" />
            </key-property>
            <key-property name="title" type="string">
                <column name="title" length="50" />
            </key-property>
            <key-property name="category" type="integer">
                <column name="category" />
            </key-property>
            <key-property name="validity" type="integer">
                <column name="validity" />
            </key-property>
            <key-property name="unit" type="string">
                <column name="unit" length="10" />
            </key-property>
            <key-property name="price" type="string">
                <column name="price" length="10" />
            </key-property>
            <key-property name="revise" type="string">
                <column name="revise" length="10" />
            </key-property>
            <key-property name="gross" type="string">
                <column name="gross" length="10" />
            </key-property>
            <key-property name="deadline" type="string">
                <column name="deadline" length="10" />
            </key-property>
            <key-property name="explain" type="string">
                <column name="explain" length="1000" />
            </key-property>
            <key-property name="imgurl" type="string">
                <column name="imgurl" length="100" />
            </key-property>
            <key-property name="condition" type="integer">
                <column name="condition" />
            </key-property>
           <key-property name="times" type="timestamp">
                <column name="times" length="16" />
            <key-property>
            <key-property name="retainday" type="integer">
                <column name="retainday" />
            <key-property>
           <key-property name="report" type="string">
                <column name="report" length="50" />
            <key-property>
          <key-property name="state" type="integer">
               <column name="state" />
            <key-property>
        <composite-id>
    </class>
</hibernate-mapping>

 


这些我都用myeclipse自动生成的,信息大家也知道,不过我怎么都查询不了!网上找了资料也不行!

List list=dao.query("FROM Productview as pr");
  Iterator iterator=list.iterator();
  while(iterator.hasNext()){
   Productview prw=(Productview)iterator.next();
   ProductviewId prid=prw.getId();
   log.info(prid.getId());
  }

抛出异常:

java.lang.NullPointerException
com.longge.action.PaginAction.ztest(PaginAction.java:503)

如果加where条件,就会抛出别一个异常,希望大家!

论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics