Browse Source

Replace usage of Hibernate's Criteria API (#4855)

Radoslav Petrov 6 years ago
parent
commit
47bdf3fe4b

+ 7 - 4
frameworks/Java/dropwizard/src/main/java/com/example/helloworld/db/hibernate/FortuneHibernateImpl.java

@@ -1,12 +1,15 @@
 package com.example.helloworld.db.hibernate;
 package com.example.helloworld.db.hibernate;
 
 
-import com.example.helloworld.db.FortuneDAO;
-import com.example.helloworld.db.model.Fortune;
 import io.dropwizard.hibernate.AbstractDAO;
 import io.dropwizard.hibernate.AbstractDAO;
-import org.hibernate.SessionFactory;
 
 
 import java.util.List;
 import java.util.List;
 
 
+import org.hibernate.SessionFactory;
+import org.hibernate.query.Query;
+
+import com.example.helloworld.db.FortuneDAO;
+import com.example.helloworld.db.model.Fortune;
+
 public class FortuneHibernateImpl extends AbstractDAO<Fortune> implements FortuneDAO {
 public class FortuneHibernateImpl extends AbstractDAO<Fortune> implements FortuneDAO {
 
 
     public FortuneHibernateImpl(SessionFactory factory) {
     public FortuneHibernateImpl(SessionFactory factory) {
@@ -14,6 +17,6 @@ public class FortuneHibernateImpl extends AbstractDAO<Fortune> implements Fortun
     }
     }
 
 
     public List<Fortune> list() {
     public List<Fortune> list() {
-        return list(criteria());
+        return list((Query<Fortune>) query("SELECT f FROM Fortune f"));
     }
     }
 }
 }

+ 0 - 1
frameworks/Java/dropwizard/src/main/java/com/example/helloworld/db/model/Fortune.java

@@ -16,7 +16,6 @@ public class Fortune implements Comparable<Fortune> {
     @Column(name = "message", nullable = false)
     @Column(name = "message", nullable = false)
     private String message;
     private String message;
 
 
-    @SuppressWarnings("unused")
     public Fortune() {}
     public Fortune() {}
     
     
     public Fortune(String message) {
     public Fortune(String message) {