Using XMLType in Oracle XE-Database with Eclipselink [message #388428] |
Tue, 26 May 2009 12:14 |
Johannes Michler Messages: 21 Registered: July 2009 |
Junior Member |
|
|
Hi,
I'm trying to connect to an Oracle 10g Express Database using
eclipselink JPA.
My Database has the following table:
CREATE TABLE "SYSTEM"."TEST_MODELL"
( "EMPL_ID" NUMBER NOT NULL ENABLE,
"EMPLOYEEDATEN" "SYS"."XMLTYPE" ,
CONSTRAINT "TEST_MODELL_PK" PRIMARY KEY ("EMPL_ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "SYSTEM" ENABLE
) XMLTYPE COLUMN "EMPLOYEEDATEN" XMLSCHEMA
"http://www.horus.biz/RoleEmployee.xsd" ELEMENT "employee" ID 2411
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "SYSTEM" ;
My initial idea for the Entity-Class was as following:
@Entity
@Table(name="TEST_MODELL")
public class TestModell implements Serializable {
@Id
@Column(name="EMPL_ID")
private long emplId;
@Column(name="employeedaten",columnDefinition="XMLTYPE")
private String employeedaten;
.....
}\
I created an entitymanager (using the thin oracle-jdbc) and did the
following query:
Query query = getEntityManager().createQuery("Select p from TestModell p");
return query.getResultList();
This allways gives me employeedaten to be a String meaning
"oracle.sql.OPAQUE@16cf4f9".
I then changed the type of employeedaten in my Testmodell class from
String to org.w3c.dom.Documen. This gave me the following JPA-exception:
Entity class [class testplugin.model.TestModell] must use a @JoinColumn
instead of @Column to map its relationship attribute [employeedaten].
Changing Column to JoinColumn results in an invalid sql-statement
generated by the query:
[EL Fine]: Connection(20298030)--SELECT EMPL_ID, employeedaten, DTYPE
FROM TEST_MODELL
[EL Fine]: SELECT 1 FROM DUAL
[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services
- 1.1.1.v20090430-r4097):
org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-00904: "DTYPE": invalid
identifier
Error Code: 904
I finally found some hints to use a Direct-To-Xml-Mapping. So I removed
the annotations on the employeedaten-Column and added
@Customizer(value=XmlDataCustomizer.class) to the TestModell-class,
where my Customizer is as follows:
public class XmlDataCustomizer implements DescriptorCustomizer {
public void customize(final ClassDescriptor descriptor) throws
Exception {
descriptor.removeMappingForAttributeName("employeedaten");
DirectToXMLTypeMapping mapping = new DirectToXMLTypeMapping();
// mapping.setShouldReadWholeDocument(true);
mapping.setAttributeName("employeedaten");
mapping.setFieldName("EMPLOYEEDATEN");
// mapping.setIsLazy(false);
descriptor.addMapping(mapping);
}
}
This gives me the following exception when executing:
[EL Fine]: Connection(18938218)--SELECT EMPL_ID, EMPLOYEEDATEN FROM
TEST_MODELL
[EL Warning]: Exception [EclipseLink-3001] (Eclipse Persistence Services
- 1.1.1.v20090430-r4097):
org.eclipse.persistence.exceptions.ConversionException
Exception Description: The object [oracle.sql.OPAQUE@5e34ce], of class
[class oracle.sql.OPAQUE], could not be converted to [interface
org.w3c.dom.Document].
Internal Exception: java.lang.ClassCastException: oracle.sql.OPAQUE
cannot be cast to java.lang.String
Changing the type of employeedaten from w3c-document back to String
didn't help, the error then is:
[EL Fine]: Connection(20646012)--SELECT EMPL_ID, EMPLOYEEDATEN FROM
TEST_MODELL
[EL Warning]: Exception [EclipseLink-32] (Eclipse Persistence Services -
1.1.1.v20090430-r4097):
org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Trying to set value [oracle.sql.OPAQUE@2bc29] for
instance variable [employeedaten] of type [java.lang.String] in the
object. The specified object is not an instance of the class or
interface declaring the underlying field, or an unwrapping conversion
has failed.
Internal Exception: java.lang.IllegalArgumentException: Can not set
java.lang.String field testplugin.model.TestModell.employeedaten to
oracle.sql.OPAQUE
Mapping:
org.eclipse.persistence.mappings.xdb.DirectToXMLTypeMapping[ employeedaten-- >TEST_MODELL.EMPLOYEEDATEN]
Descriptor: RelationalDescriptor(testplugin.model.TestModell -->
[DatabaseTable(TEST_MODELL)])
What else could I do to access an XML-Field in an oracle-XE Database
using Eclipselink? JPA/Eclipselink and the jdbc-driver seem to be setup
correctly, since a simple database without xml-fields is working quite fine.
Any help would be higly appreciated,
best regards
Franz
|
|
|
|
Powered by
FUDForum. Page generated in 0.02367 seconds