From 1870e19320793fe3f3c4e9ce80469f0fa7ee258f Mon Sep 17 00:00:00 2001 From: Richard Eckart de Castilho Date: Tue, 31 Oct 2023 15:43:24 +0100 Subject: [PATCH] #264 - Compiler error in Eclipse only - Add explicit cast to work around the problem reported by the Eclipse compiler --- .../java/org/dkpro/jwpl/api/Wikipedia.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/dkpro-jwpl-api/src/main/java/org/dkpro/jwpl/api/Wikipedia.java b/dkpro-jwpl-api/src/main/java/org/dkpro/jwpl/api/Wikipedia.java index d6ab26a6..e3e313d6 100644 --- a/dkpro-jwpl-api/src/main/java/org/dkpro/jwpl/api/Wikipedia.java +++ b/dkpro-jwpl-api/src/main/java/org/dkpro/jwpl/api/Wikipedia.java @@ -36,6 +36,7 @@ import org.dkpro.jwpl.api.hibernate.WikiHibernateUtil; import org.dkpro.jwpl.util.distance.LevenshteinStringDistance; import org.hibernate.Session; +import org.hibernate.query.NativeQuery; import org.hibernate.type.StandardBasicTypes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -753,10 +754,10 @@ public Language getLanguage() */ public boolean existsPage(String title) { - if (title == null || title.isEmpty()) { return false; } + Title t; try { t = new Title(title); @@ -764,19 +765,27 @@ public boolean existsPage(String title) catch (WikiTitleParsingException e) { return false; } + String encodedTitle = t.getWikiStyleTitle(); Session session = this.__getHibernateSession(); - session.beginTransaction(); - String query = "select p.id from PageMapLine as p where p.name = :pName"; - if (dbConfig.supportsCollation()) { - query += SQL_COLLATION; - } - Object returnValue = session.createNativeQuery(query) - .setParameter("pName", encodedTitle, StandardBasicTypes.STRING).uniqueResult(); - session.getTransaction().commit(); + try { + session.beginTransaction(); + var query = "select p.id from PageMapLine as p where p.name = :pName"; + if (dbConfig.supportsCollation()) { + query += SQL_COLLATION; + } - return returnValue != null; + // Eclipse somehow thinks that setParameter returns a MutationQuery instead of a + // NativeQuery... + var nativeQuery = (NativeQuery) session.createNativeQuery(query) // + .setParameter("pName", encodedTitle, StandardBasicTypes.STRING); + var returnValue = nativeQuery.uniqueResult(); + return returnValue != null; + } + finally { + session.getTransaction().commit(); + } } /**