ERLEDIGT
NEIN
NEIN
ANTWORTEN
1
1
ZUGRIFFE
793
793
EMPFEHLEN
-
Hallo,
ich möchte mittels Hibernate Criteria folgende Abfrage ausführen:
Code java:1 2 3 4 5 6 7 8 9 10 11 12 13 14
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.
Code java:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
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; } }
Code java:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
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ß
ThomasGeändert von toroe (06.07.09 um 07:27 Uhr)
-
07.07.09 10:29 #2
Ähm... wo bitte siehst du in der Klasse TestView03 eine Property "date"?
In theory, there is no difference between theory and practice. In practice, there is!
www.olivergierke.de
Ähnliche Themen
-
Criteria: zwei criteria Objekte "oder-verknüpfen"?
Von RoCMe im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 0Letzter Beitrag: 25.05.10, 17:31 -
Hibernate Criteria-Abfrage über mehrere Objekte
Von pizza1234 im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 2Letzter Beitrag: 18.03.10, 10:02 -
Hibernate Criteria Javassist
Von langmar im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 6Letzter Beitrag: 27.08.09, 18:05 -
Problem Oder-Verknüpfung Hibernate-Criteria
Von pizza1234 im Forum JavaAntworten: 2Letzter Beitrag: 08.04.09, 10:34 -
Spring und Hibernate (Criteria & Query by Example) problem
Von catarina im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 2Letzter Beitrag: 07.04.09, 14:42





Zitieren
Login





