Hallo,
ich möchte mittels Hibernate Criteria folgende Abfrage ausführen:
Dazu habe ich mit Eclipse zwei Klassen generieren lassen.
Leider erhalte ich nur die Fehlermeldung :
Exception in thread "main" org.hibernate.QueryException: could not resolve property: date of: hbm.TestView03
Was mache ich falsch ?
Gruß
Thomas
ich möchte mittels Hibernate Criteria folgende Abfrage ausführen:
Java:
SimpleDateFormat df = new SimpleDateFormat("d.M.y");
sess = InitSessionFactory.getInstance().getCurrentSession();
Transaction trx = sess.beginTransaction();
Criteria crit = sess.createCriteria(TestView03.class);
crit.add(Restrictions.ge("date", df.parse("1.1.2009")));
List<TestView03Id> erg = crit.list();
for (TestView03Id TestView03Id : erg) {
System.out.println(TestView03Id.getName());
}
Dazu habe ich mit Eclipse zwei Klassen generieren lassen.
Java:
package hbm;
// Generated 06.07.2009 06:19:14 by Hibernate Tools 3.2.4.CR1
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
* TestView03 generated by hbm2java
*/
@Entity
@Table(name = "test_view_03", schema = "dbo", catalog = "Test")
public class TestView03 implements java.io.Serializable {
private TestView03Id id;
public TestView03() {
}
public TestView03(TestView03Id id) {
this.id = id;
}
@EmbeddedId
@AttributeOverrides( {
@AttributeOverride(name = "name", column = @Column(name = "name", nullable = false, length = 10)) ,
@AttributeOverride(name = "nr", column = @Column(name = "nr", nullable = false, length = 10)) ,
@AttributeOverride(name = "date", column = @Column(name = "date", nullable = false, length = 23)) ,
@AttributeOverride(name = "text", column = @Column(name = "text")) })
public TestView03Id getId() {
return this.id;
}
public void setId(TestView03Id id) {
this.id = id;
}
}
Java:
package hbm;
// Generated 06.07.2009 06:19:14 by Hibernate Tools 3.2.4.CR1
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Embeddable;
/**
* TestView03Id generated by hbm2java
*/
@Embeddable
public class TestView03Id implements java.io.Serializable {
private String name;
private String nr;
private Date date;
private String text;
public TestView03Id() {
}
public TestView03Id(String name, String nr, Date date) {
this.name = name;
this.nr = nr;
this.date = date;
}
public TestView03Id(String name, String nr, Date date, String text) {
this.name = name;
this.nr = nr;
this.date = date;
this.text = text;
}
@Column(name = "name", nullable = false, length = 10)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@Column(name = "nr", nullable = false, length = 10)
public String getNr() {
return this.nr;
}
public void setNr(String nr) {
this.nr = nr;
}
@Column(name = "date", nullable = false, length = 23)
public Date getDate() {
return this.date;
}
public void setDate(Date date) {
this.date = date;
}
@Column(name = "text")
public String getText() {
return this.text;
}
public void setText(String text) {
this.text = text;
}
public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof TestView03Id))
return false;
TestView03Id castOther = (TestView03Id) other;
return ((this.getName() == castOther.getName()) || (this.getName() != null && castOther.getName() != null && this.getName().equals(
castOther.getName())))
&& ((this.getNr() == castOther.getNr()) || (this.getNr() != null && castOther.getNr() != null && this.getNr().equals(
castOther.getNr())))
&& ((this.getDate() == castOther.getDate()) || (this.getDate() != null && castOther.getDate() != null && this.getDate()
.equals(castOther.getDate())))
&& ((this.getText() == castOther.getText()) || (this.getText() != null && castOther.getText() != null && this.getText()
.equals(castOther.getText())));
}
public int hashCode() {
int result = 17;
result = 37 * result + (getName() == null ? 0 : this.getName().hashCode());
result = 37 * result + (getNr() == null ? 0 : this.getNr().hashCode());
result = 37 * result + (getDate() == null ? 0 : this.getDate().hashCode());
result = 37 * result + (getText() == null ? 0 : this.getText().hashCode());
return result;
}
}
Leider erhalte ich nur die Fehlermeldung :
Exception in thread "main" org.hibernate.QueryException: could not resolve property: date of: hbm.TestView03
Was mache ich falsch ?
Gruß
Thomas
Zuletzt bearbeitet: