From 4503ccac99bc10c8e857cbc2537e2410e14c9112 Mon Sep 17 00:00:00 2001 From: Drew Short Date: Sun, 9 Feb 2014 18:15:43 -0600 Subject: [PATCH] Fixed issues with the persistence engine not being able to retrieve already processed images. --- src/main/resources/hibernate/Image.hbm.xml | 8 ++++---- .../scala/com/sothr/imagetools/dao/ImageDAO.scala | 13 ++++--------- .../com/sothr/imagetools/image/ImageService.scala | 2 +- src/test/resources/hibernate/Image.hbm.xml | 8 ++++---- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/main/resources/hibernate/Image.hbm.xml b/src/main/resources/hibernate/Image.hbm.xml index 64e2b56..bdc5126 100644 --- a/src/main/resources/hibernate/Image.hbm.xml +++ b/src/main/resources/hibernate/Image.hbm.xml @@ -8,9 +8,9 @@ This class contains the image hashes and meta data - - - - + + + + \ No newline at end of file diff --git a/src/main/scala/com/sothr/imagetools/dao/ImageDAO.scala b/src/main/scala/com/sothr/imagetools/dao/ImageDAO.scala index 7047fc7..4bc530f 100644 --- a/src/main/scala/com/sothr/imagetools/dao/ImageDAO.scala +++ b/src/main/scala/com/sothr/imagetools/dao/ImageDAO.scala @@ -9,31 +9,26 @@ import com.sothr.imagetools.image.Image class ImageDAO { private val sessionFactory:SessionFactory = HibernateUtil.getSessionFactory() - private val example:Image = new Image() def find(path:String):Image = { val session:Session = sessionFactory.getCurrentSession - session.beginTransaction - val result = session.get(example.getClass, path).asInstanceOf[Image] + session.getTransaction.begin() + val result = session.get(classOf[Image], path).asInstanceOf[Image] session.getTransaction.commit() result } def save(image:Image) = { val session:Session = sessionFactory.getCurrentSession - session.beginTransaction - + session.getTransaction.begin() session.saveOrUpdate(image) - session.getTransaction.commit() } def save(images:List[Image]) = { val session:Session = sessionFactory.getCurrentSession - session.beginTransaction - + session.getTransaction.begin() for (image <- images) session.saveOrUpdate(image) - session.getTransaction.commit() } diff --git a/src/main/scala/com/sothr/imagetools/image/ImageService.scala b/src/main/scala/com/sothr/imagetools/image/ImageService.scala index 46bd967..de49a73 100644 --- a/src/main/scala/com/sothr/imagetools/image/ImageService.scala +++ b/src/main/scala/com/sothr/imagetools/image/ImageService.scala @@ -48,7 +48,7 @@ object ImageService extends Logging { try { imageDAO.save(image) } catch { - case ex:Exception => error(s"Error saving up \'${image.imagePath}\' to database", ex) + case ex:Exception => error(s"Error saving \'${image.imagePath}\' to database", ex) } image } diff --git a/src/test/resources/hibernate/Image.hbm.xml b/src/test/resources/hibernate/Image.hbm.xml index 64e2b56..bdc5126 100644 --- a/src/test/resources/hibernate/Image.hbm.xml +++ b/src/test/resources/hibernate/Image.hbm.xml @@ -8,9 +8,9 @@ This class contains the image hashes and meta data - - - - + + + + \ No newline at end of file