-->
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.  [ 4 posts ] 
Author Message
 Post subject: date::date in Hibernate formulieren
PostPosted: Sun Apr 05, 2009 5:39 am 
Newbie

Joined: Sun Apr 05, 2009 5:18 am
Posts: 2
Hallo,

ich habe eine Tabelle erzeugt in der das Datum mit timestamp geseichert wird.

Code:
CREATE TABLE item
(
  id bigint NOT NULL,
  date timestamp without time zone,
  username character varying(15) NOT NULL,
  host bigint,
  application bigint,
  CONSTRAINT item_pkey1 PRIMARY KEY (id),
  CONSTRAINT fk22ef337af172d2 FOREIGN KEY (application)
      REFERENCES application (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT fk22ef338c73775e FOREIGN KEY (host)
      REFERENCES host (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (OIDS=FALSE);
ALTER TABLE item OWNER TO application_logging;


Nun möchte ich abfragen wie viele Einträge es pro Tag gab. In SQL mache ich das mit der Abfrage

Code:
select date::date, count(date::date) from item where application=21443 group by date::date order by date::date

Wenn ich es nun mit Hibernate versuche bekomme ich die Fehlermeldung

Abfrage
Code:
Query q = session.createSQLQuery(
   "select date::date, count(date::date) from item " +
   "where application = 21443 " +
   "group by date::date order by date::date)");
            
    List results = q.list()


Fehlermeldung
Code:
Exception in thread "main" org.hibernate.QueryException: Not all named parameters have been set: [:date] [select date::date, count(date::date) from item where application = 21443 group by date::date order by date::date)]


Hat jemand eine Idee wie ich den Konstrukt date::date in Hibernate formulieren muss.

Danke für Eure Hilfe
Christian


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 05, 2009 5:14 pm 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Die Syntax date::date ist mir neu, ist sicher nicht im SQL-Standard.

Normalerweise solltest du die gleiche Funktionalität mit den jeweiligen Date-Funktionen deines DBMS erreichen können, z.b.:
Code:
select day(date), month(date), year(date), count(*) from Item where application=21443 group by day(date), month(date), year(date)

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Loesung mittels View
PostPosted: Mon Apr 06, 2009 6:23 am 
Newbie

Joined: Sun Apr 05, 2009 5:18 am
Posts: 2
Das geht leider nicht. Mein Postgres meint dann

Code:
select day(date), month(date), year(date), count(*) from Item where application=21443 group by day(date), month(date), year(date);
ERROR:  function day(timestamp without time zone) does not exist
LINE 1: select day(date), month(date), year(date), count(*) from Ite...
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.


Ich habe es nun mit einer View geloest.

Code:
\d view_item_date
          View "public.view_item_date"
   Column    |         Type          | Modifiers
-------------+-----------------------+-----------
id          | bigint                |
date        | date                  |
username    | character varying(15) |
host        | bigint                |
application | bigint                |
View definition:
SELECT item.id, item.date::date AS date, item.username, item.host, item.application
   FROM item;


Auf diese Weise kann ich wieder eine normale Abfrage machen.

Danke fuer den Hinweis.

Christian[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 06, 2009 9:27 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Kenn mich mit Postgres nicht aus, aber ich glaube, da erhältst du z.B. den Tag über die extract-Funktion, sodass Folgendes funktionieren könnte:
Code:
select extract(day from date), extract(month from date), extract(year from date), count(*) from Item


Rating ist willkommen. ;-)

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.