3636import org .hibernate .criterion .Projections ;
3737import org .hibernate .criterion .Property ;
3838import org .hibernate .criterion .Restrictions ;
39- import org .hibernate .query .NativeQuery ;
4039import org .hibernate .transform .Transformers ;
4140
4241import de .bielefeld .umweltamt .aui .HibernateSessionFactory ;
@@ -124,7 +123,8 @@ public static List<Adresse> getAdresse(String property, String search) {
124123 query += " AND adresse.deleted = false" ;
125124 query += " ORDER BY adresse.betrname ASC, adresse.betrnamezus ASC" ;
126125
127- return HibernateSessionFactory .currentSession ().createQuery (query ).list ();
126+ return HibernateSessionFactory .currentSession ()
127+ .createQuery (query , Adresse .class ).list ();
128128 }
129129
130130 /**
@@ -173,8 +173,8 @@ public static List<Inhaber> findBetreiber(String name, String strasse, Integer h
173173 query += " AND a.deleted = false" ;
174174 }
175175 query += " ORDER BY i.name ASC" ;
176- List list = HibernateSessionFactory .currentSession (). createQuery ( query ). list ();
177- return list ;
176+ return HibernateSessionFactory .currentSession ()
177+ . createQuery ( query , Inhaber . class ). list () ;
178178 }
179179
180180 /**
@@ -221,7 +221,8 @@ public static List<Adresse> findAdressen(String name, String strasse, Integer ha
221221
222222 query += "ORDER BY adresse.strasse ASC, adresse.hausnr ASC, adresse.hausnrzus ASC, adresse.betrname ASC" ;
223223 }
224- return HibernateSessionFactory .currentSession ().createQuery (query ).list ();
224+ return HibernateSessionFactory .currentSession ()
225+ .createQuery (query , Adresse .class ).list ();
225226 }
226227
227228 /**
@@ -268,9 +269,9 @@ public static List<Object[]> findInhaber(String strasse, Integer hausnr, String
268269 query += " AND a._deleted = false" ;
269270 }
270271 query += " ORDER BY a.strasse ASC, a.hausnr ASC, a.hausnrzus ASC NULLS FIRST;" ;
271- NativeQuery q = HibernateSessionFactory .currentSession (). createSQLQuery ( query );
272- q . addEntity ( "i" , Inhaber .class );
273- return q . list ();
272+ return HibernateSessionFactory .currentSession ()
273+ . createNativeQuery ( query , Object [] .class )
274+ . getResultList ();
274275 }
275276
276277 /**
@@ -299,8 +300,7 @@ public static String getBetriebsgrundstueck(Adresse betreiber) {
299300 * String
300301 * @return <code>List<Adresse[]></code>
301302 */
302-
303- public static List <Adresse > findAdressen (String search , String property ) {
303+ public static List <Inhaber > findAdressen (String search , String property ) {
304304
305305 String query = "SELECT inh " + "FROM Adresse adresse, Inhaber inh" ;
306306
@@ -309,7 +309,8 @@ public static List<Adresse> findAdressen(String search, String property) {
309309 query += "LOWER(inh.name) like '" + search .toLowerCase () + "%' AND adresse.deleted = false" ;
310310
311311 query += " ORDER BY adresse.strasse ASC, adresse.hausnr ASC, adresse.hausnrzus ASC, inh.name ASC" ;
312- return HibernateSessionFactory .currentSession ().createQuery (query ).list ();
312+ return HibernateSessionFactory .currentSession ()
313+ .createQuery (query , Inhaber .class ).list ();
313314 }
314315
315316 /**
@@ -363,7 +364,8 @@ else if (bName && property.equals("zusatz")) {
363364
364365 query += "ORDER BY a.strasse ASC, a.hausnr ASC, a.hausnrzus ASC, i.name ASC" ;
365366 }
366- return HibernateSessionFactory .currentSession ().createQuery (query ).list ();
367+ return HibernateSessionFactory .currentSession ()
368+ .createQuery (query , Inhaber .class ).list ();
367369 }
368370
369371 /**
@@ -391,8 +393,8 @@ public static List<Adresse> findAdressen(String strasse, Integer hausnr, String
391393 query += "adresse.plz = '" + plz + "' AND " ;
392394 query += "adresse.deleted = false " ;
393395
394- List < Adresse > list = HibernateSessionFactory .currentSession (). createQuery ( query ). list ();
395- return list ;
396+ return HibernateSessionFactory .currentSession ()
397+ . createQuery ( query , Adresse . class ). list () ;
396398 }
397399
398400 public static List <Adresse > findAdressen (String strasse , Integer hausnr ) {
@@ -414,8 +416,8 @@ public static List<Adresse> findAdressen(String strasse, Integer hausnr) {
414416
415417 query += "ORDER BY adresse.strasse ASC, adresse.hausnr ASC, adresse.hausnrzus ASC " ;
416418 }
417- List < Adresse > list = HibernateSessionFactory .currentSession (). createQuery ( query ). list ();
418- return list ;
419+ return HibernateSessionFactory .currentSession ()
420+ . createQuery ( query , Adresse . class ). list () ;
419421 }
420422
421423
@@ -484,7 +486,8 @@ public static List<Adresse> findStandorte(String strasse, Integer hausnr, String
484486 query += " AND o.deleted = false" ;
485487 }
486488 query += " ORDER BY a.strasse ASC, a.hausnr ASC, a.hausnrzus ASC" ;
487- return HibernateSessionFactory .currentSession ().createQuery (query ).list ();
489+ return HibernateSessionFactory .currentSession ()
490+ .createQuery (query , Adresse .class ).list ();
488491 }
489492
490493 public static List <Standort > chooseStandort (String strasse , Integer hausnr , String ort ) {
@@ -518,7 +521,8 @@ public static List<Standort> chooseStandort(String strasse, Integer hausnr, Stri
518521 query += " AND a.deleted = false" ;
519522 }
520523 query += " ORDER BY a.strasse ASC, a.hausnr ASC, a.hausnrzus ASC" ;
521- return HibernateSessionFactory .currentSession ().createQuery (query ).list ();
524+ return HibernateSessionFactory .currentSession ()
525+ .createQuery (query , Standort .class ).list ();
522526 }
523527
524528 /**
@@ -548,7 +552,8 @@ public static List<Standort> findStandorte(String search, String property) {
548552 query += "a.deleted = false" ;
549553
550554 query += " ORDER BY a.strasse ASC, a.hausnr ASC, a.hausnrzus ASC, i.name ASC" ;
551- return HibernateSessionFactory .currentSession ().createQuery (query ).list ();
555+ return HibernateSessionFactory .currentSession ()
556+ .createQuery (query , Standort .class ).list ();
552557 }
553558
554559 public static Standort findStandort (Inhaber inh ) {
@@ -660,10 +665,9 @@ public static List<Objekt> getObjekteByInhaber(Inhaber inh, String abteilung, In
660665 }
661666 query += " ORDER BY o.inaktiv, o.objektartid" ;
662667
663- NativeQuery q = HibernateSessionFactory .currentSession ().createSQLQuery (query );
664-
665- q .addEntity ("o" , Objekt .class );
666- return q .list ();
668+ return HibernateSessionFactory .currentSession ()
669+ .createNativeQuery (query , Objekt .class )
670+ .getResultList ();
667671 }
668672
669673 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -696,9 +700,9 @@ public static List<Objekt> getObjekteByStandort(Adresse adr, String abteilung, I
696700 }
697701 }
698702 query += " ORDER BY o.inaktiv, o.objektartid" ;
699- NativeQuery q = HibernateSessionFactory .currentSession (). createSQLQuery ( query );
700- q . addEntity ( "o" , Objekt .class );
701- return q . list ();
703+ return HibernateSessionFactory .currentSession ()
704+ . createNativeQuery ( query , Objekt .class )
705+ . getResultList ();
702706 }
703707
704708 public static List <Objekt > getObjekteByStandort (Objekt obj ) {
@@ -709,9 +713,9 @@ public static List<Objekt> getObjekteByStandort(Objekt obj) {
709713 + " WHERE o.standortid = '" + stdId + "'" ;
710714
711715 query += " ORDER BY o.inaktiv, o.objektartid" ;
712- NativeQuery q = HibernateSessionFactory .currentSession (). createSQLQuery ( query );
713- q . addEntity ( "o" , Objekt .class );
714- return q . list ();
716+ return HibernateSessionFactory .currentSession ()
717+ . createNativeQuery ( query , Objekt .class )
718+ . getResultList ();
715719 }
716720
717721 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -1008,31 +1012,30 @@ public static List<String> getAllTabStreetslist() {
10081012
10091013 String query = "SELECT DISTINCT name " + "FROM TabStreets ORDER BY name" ;
10101014
1011- return HibernateSessionFactory .currentSession (). createQuery ( query ). list ();
1012-
1015+ return HibernateSessionFactory .currentSession ()
1016+ . createQuery ( query , String . class ). list ();
10131017 }
10141018
10151019 /**
1016- * Get all BasisTabStreets and sort them by their name
1020+ * Get arbitrary street name that starts with search string.
10171021 *
1018- * @return <code>Eine Liste aller Stassen</code>
1022+ * @param search search string
1023+ * @return street name
10191024 */
10201025 public static String getTabStreet (String search ) {
10211026
10221027 String query = "SELECT DISTINCT name "
10231028 + "FROM TabStreets "
10241029 + "WHERE LOWER(name) like '" + search .toLowerCase () + "%'" ;
10251030
1026- List strasse = HibernateSessionFactory .currentSession ().createQuery (query ).list ();
1027-
1028- return (strasse .isEmpty () ? null : strasse .get (0 ).toString ());
1031+ List <String > strasse = HibernateSessionFactory .currentSession ()
1032+ .createQuery (query , String .class ).list ();
10291033
1034+ return (strasse .isEmpty () ? null : strasse .get (0 ));
10301035 }
10311036
10321037 /**
1033- * Get all BasisTabStreets and sort them by their name
1034- *
1035- * @return <code>Eine Liste aller Stassen</code>
1038+ * Get arbitrary street that matches given parameters.
10361039 */
10371040 public static TabStreets getSingleTabStreet (String name , Integer hausnr , String hausnrzus ) {
10381041
@@ -1052,9 +1055,10 @@ public static TabStreets getSingleTabStreet(String name, Integer hausnr, String
10521055 }
10531056 }
10541057
1055- List tabStreet = HibernateSessionFactory .currentSession ().createQuery (query ).list ();
1058+ List <TabStreets > tabStreet = HibernateSessionFactory .currentSession ()
1059+ .createQuery (query , TabStreets .class ).list ();
10561060
1057- return ( TabStreets ) tabStreet .iterator ().next ();
1061+ return tabStreet .iterator ().next ();
10581062
10591063 }
10601064
@@ -1167,7 +1171,8 @@ public static List<Anhang> allActiveAnhangs() {
11671171 String query = "FROM Anhang WHERE anh_gueltig_bis IS NULL " +
11681172 "ORDER BY CAST (NULLIF(regexp_replace(anhang_id, '\\ D', '', 'g'), '') as int) asc" ;
11691173
1170- return HibernateSessionFactory .currentSession ().createQuery (query ).list ();
1174+ return HibernateSessionFactory .currentSession ()
1175+ .createQuery (query , Anhang .class ).list ();
11711176 }
11721177
11731178 /**
@@ -1181,7 +1186,8 @@ public static List<Abaverfahren> getNwAbaVerfahrens() {
11811186 String query = "FROM Abaverfahren WHERE bezeichnung LIKE '34.%' " +
11821187 "ORDER BY bezeichnung asc" ;
11831188
1184- return HibernateSessionFactory .currentSession ().createQuery (query ).list ();
1189+ return HibernateSessionFactory .currentSession ()
1190+ .createQuery (query , Abaverfahren .class ).list ();
11851191 }
11861192
11871193 /* ********************************************************************** */
@@ -1243,7 +1249,7 @@ public static List<Wasserrecht> findWasserrechtGenDatum(Date search) {
12431249 * - BAsisAbfrage.VALUE_WIEDERVORLAGE_ABGELAUFEN
12441250 * @return Object array containing results
12451251 */
1246- public static List executeBaseQuery (
1252+ public static List < Object []> executeBaseQuery (
12471253 Objektarten art , Anhang anhang , String anlagenart ,
12481254 Sachbearbeiter sachbearbeiter , String [] entwGebiet ,
12491255 String prioritaet , String wiedervorlage ,
@@ -1338,9 +1344,9 @@ public static List executeBaseQuery(
13381344 query .append ("'" + today + "'" );
13391345 }
13401346 query .append (";" );
1341- NativeQuery < Object > q = HibernateSessionFactory .currentSession ()
1342- . createSQLQuery (query .toString ());
1343- return q .getResultList ();
1347+ return HibernateSessionFactory .currentSession ()
1348+ . createNativeQuery (query .toString (), Object []. class )
1349+ .getResultList ();
13441350 }
13451351
13461352 /* ********************************************************************** */
0 commit comments