@@ -145,9 +145,7 @@ public CompletableFuture<E> findByFieldNames(Map<String, Object> entries) {
145145 session .beginTransaction ();
146146 String hql = "FROM " + entityClass .getName () + (entries .size () > 0 ? " WHERE " : "" );
147147
148- hql += entries .entrySet ().stream ().map (entry -> {
149- return entry .getKey () + " = :" +entry .getKey ();
150- }).collect (Collectors .joining (" AND " ));
148+ hql += entries .keySet ().stream ().map (object -> object + " = :" + object ).collect (Collectors .joining (" AND " ));
151149
152150
153151 Query <E > query = session .createQuery (hql , entityClass );
@@ -163,4 +161,33 @@ public CompletableFuture<E> findByFieldNames(Map<String, Object> entries) {
163161 }
164162 });
165163 }
164+
165+ @ Override
166+ public CompletableFuture <List <E >> findManyByFieldName (String name , Object value ) {
167+ return this .findManyByFieldNames (Map .of (name , value ));
168+ }
169+
170+ @ Override
171+ public CompletableFuture <List <E >> findManyByFieldNames (Map <String , Object > entries ) {
172+ return CompletableFuture .supplyAsync (() -> {
173+ try (Session session = this .sessionFactory .openSession ()) {
174+ session .beginTransaction ();
175+ String hql = "FROM " + entityClass .getName () + (entries .size () > 0 ? " WHERE " : "" );
176+
177+ hql += entries .keySet ().stream ().map (object -> object + " = :" + object ).collect (Collectors .joining (" AND " ));
178+
179+
180+ Query <E > query = session .createQuery (hql , entityClass );
181+
182+ for (int i = 0 ; i < entries .size (); i ++) {
183+ query .setParameter (entries .keySet ().stream ().toList ().get (i ), entries .values ().stream ().toList ().get (i ));
184+ }
185+
186+ List <E > result = query
187+ .getResultList ();
188+ session .getTransaction ().commit ();
189+ return result ;
190+ }
191+ });
192+ }
166193}
0 commit comments