On 01/06/2011 01:18 PM, Caleb James DeLisle wrote:
On 01/06/2011 07:00 AM, Caleb James DeLisle wrote:
The problem is that you are using SQL to query against the database and Hibernate is expecting HQL. I assume you added a table called lovtestdata manually. unfortunately hibernate doesn't know that it exists and will not allow you to query against it.
The easy solution is to use: {{groovy}} xc = xcontext.getContext() hib = xc.getWiki().getHibernateStore(); hib.beginTransaction(xc); try { conn = hib.getSession().openConnection();
conn = hib.getSession().connection(); My mistake.
// conn will be a http://download.oracle.com/javase/1.3/docs/api/java/sql/Connection.html // which will give you raw access to the database.
// commit hib.endTransaction(xc, true); } catch (Exception e) { // or rollback hib.endTransaction(xc, false); throw e; } {{/groovy}}
The "right" solution is to use XObjects and query for their properties using HQL or XWQL instead of raw database queries.
Caleb
On 01/06/2011 05:09 AM, Richardson Luke wrote:
Hi All,
I am having an issue with an error when running a velocity macro in xwiki.
Within the Oracle database I have a table containing a list of page names. I am trying to run a script where the system takes this list, cycles through all pages within a space and deletes any pages who's name appears on the list.
An alternative is to use the SQL plugin: http://extensions.xwiki.org/xwiki/bin/Extension/SQL+Plugin
Here's what I have so far...
.... #set($sql = " where doc.space='AlarmIdentifiers' AND doc.name IN (SELECT data FROM lovtestdata)") #DeletePagesLocal($sql) ....
#macro(DeletePagesLocal $sql) #foreach($item in $xwiki.searchDocuments($sql)) #set($itemdoc = $xwiki.getDocument($item)) $itemdoc.delete() #end #end
The error I am getting is:
Caused by: com.xpn.xwiki.XWikiException: Error number 3223 in 3: Exception while searching documents with SQL [select distinct doc.space, doc.name from XWikiDocument as doc where (doc.hidden<> true or doc.hidden is null) and doc.space='AlarmIdentifiers' AND doc.name IN (SELECT data FROM lovtestdata)] Wrapped Exception: lovtestdata is not mapped [select distinct doc.space, doc.name from com.xpn.xwiki.doc.XWikiDocument as doc where (doc.hidden<> true or doc.hidden is null) and doc.space='AlarmIdentifiers' AND doc.name IN (SELECT data FROM lovtestdata)]
Essentially it is saying that the table is not mapped.
If anyone could point me in the right direction it would be great.
Many thanks Luke
-- Sergiu Dumitriu http://purl.org/net/sergiu/