I have a table with an XMLType column, so I created a custom UserType that also implements ParameterizedType, which I use to get the desired JAXB annotated type to marshall/unmarshall the XML once it's retrieved. Whenever I use a native query or SQL query, I get a null pointer because the parameters are null. If I use criteria or HQL, the parameters are in tact.
Here's my code:
HBM:
Code:
<hibernate-mapping>
<class name="sandbox.ds012781.dao.entity.XmlTypeTestEntity"
table="XMLTYPETEST">
<id name="id" type="java.lang.Long" column="ID">
<generator class="seqhilo">
<param name="sequence">SEQ</param>
<param name="max_lo">100</param>
</generator>
</id>
<property name="xml">
<type name="sandbox.ds012781.hbn.XmlSerializableType">
<param name="packages">sandbox.ds012781.types</param>
<param name="class">sandbox.ds012781.types.Profile</param>
</type>
</property>
</class>
</hibernate-mapping>
Entity:
Code:
public class XmlTypeTest {
private Long id;
private Profile xml;
// getters/setters
}
DAO snippet
Code:
private static final String SUBMITTER_ID_QUERY = "SELECT id as \"id\", extract(x.xml, 'Profile[submitterId=\"%s\"]') \"xml\" FROM xmltypetest x WHERE existsNode(x.xml, 'Profile[submitterId=\"%s\"]') = 1";
@SuppressWarnings("unchecked")
public List<XmlTypeTestEntity> findBySubscriberId(String submitterId)
{
return getSession().createCriteria(XmlTypeTestEntity.class).list();
//return getSession().createSQLQuery(String.format(SUBMITTER_ID_QUERY, submitterId, submitterId)).addScalar("id", Hibernate.LONG).addScalar("xml").setResultTransformer(Transformers.aliasToBean(XmlTypeTestEntity.class)).list();
}
UserType snippet:
Code:
parameters.getProperty(CLASSNAME, null); // NPE because parameters is null
The commented out SQL query doesn't work, but the criteria does? Can someone tell me why, and how could I get the sql query to work? Thanks in advance.