-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: ParameterizedType parameters are null using SQLQuery
PostPosted: Mon Aug 30, 2010 10:45 pm 
Newbie

Joined: Mon Aug 30, 2010 10:32 pm
Posts: 2
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.