These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Query: Datensätze im LETZTEN MONAT
PostPosted: Tue Mar 30, 2010 8:01 am 
Newbie

Joined: Thu Mar 11, 2010 6:30 am
Posts: 2
Hallo,
ich bin noch ein Neuling und möchte eine Query machen, die mir Datensätze vom letzten Tag / Monat / Jahr.
Wie geht das?

Zudem wie kann ich eine parameterisiere Query machen: also, dass ich den Zeitraum einstellen kann, von dem mir die Ergebnisse angezeigt werden.
Besten Dank für eure Hilfe.


Top
 Profile  
 
 Post subject: Re: Query: Datensätze im LETZTEN MONAT
PostPosted: Thu Apr 22, 2010 9:29 am 
Newbie

Joined: Wed Apr 21, 2010 8:41 am
Posts: 12
Hallo,

du benötigst in deiner Tabelle ein Datum oder Timestamp, z.B.:
Code:
@Entity
@Table(name = "entities")   
public class Entity {
  ...

  @Column(name="CREATED")
  private Date created;

  @Column(name="UPDATED")
  private Date updated;

  @PrePersist
  protected void onCreate() {
    created = new Date();
  }

  @PreUpdate
  protected void onUpdate() {
    updated = new Date();
  }
}

Die Annotationen @PrePersist und @PreUpdate sorgen dafür dass das Erstell-Datum und das Update-Datum vor dem Insert gesetzt werden.

Jetzt kannst du mithilfe von HQL deine Query wie folge erstellen:
Code:
            Query query = entityManager.createQuery("FROM Auto where created <= :theDate");
            query.setParameter("theDate", new Date());

Grüße,
Jonas


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.