Hi all!

I have a problem, maybe someone knows how to solve it ;)

I use OpenJPA + JAXB with IBM DB2 pureXML engine.

In my entity class a have a field:

@Persistent
@Strategy ("org.apache.openjpa.jdbc.meta.strats.XMLValueHandler")
private PatientType patientinfo;

I can persist objects, retrieve them, JAXB (un)marshaling works
without any trouble.

BUT when I need to perform operations on XML documents that have a
namespace there is some trouble...

given simple select query that uses patientinfo is an XML column:

select object(o) from ErsPatient as o where o.idpatient >= 200 and
o.patientinfo.pesel = 'my_pesel_number_here'

OpenJPA generates following query:

SELECT t0.idpatient, t0.patientinfo FROM DB2ERS.ERS_PATIENTS t0 WHERE
(t0.idpatient >= ? AND XMLEXISTS('$t0.patientinfo/*[pesel = $Parm]'
PASSING t0.patientinfo AS "t0.patientinfo", CAST(? AS VARCHAR(254)) AS
"Parm"))

which is basically correct, but the result is empty list...

reason? missing namespace declaration.

when I execute native query like this (note the namespace declaration):

List<ErsPatient> list = em.createNativeQuery("SELECT t0.idpatient,
t0.patientinfo FROM DB2ERS.ERS_PATIENTS t0 WHERE (t0.idpatient >= 200
AND XMLEXISTS('declare default element namespace
\"http://www.dataweaver.org/patient\";; $t0.patientinfo/*[pesel =
$pesel]' PASSING t0.patientinfo AS \"t0.patientinfo\", CAST(?1 AS
VARCHAR(254)) AS \"pesel\"))", ErsPatient.class).setParameter(1,
"my_pesel_number_goes_here").getResultList();

every thing is OK, I have only added the declaration:

'declare default element namespace "http://www.dataweaver.org/patient";;'

maybe someone else uses OpenJPA with XML databases?

maybe OpenJPA developers have namespaces it in their road map?

thanks in advance for any help!

best regards
Łukasz

Reply via email to