-->
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.  [ 3 posts ] 
Author Message
 Post subject: PostgreSQL XML Type mapping (saving XML)
PostPosted: Tue Feb 03, 2009 10:47 am 
Newbie

Joined: Tue Feb 03, 2009 10:24 am
Posts: 2
Versions:
--Hibernate 3.2.5
--PostgreSQL 8.3

I've created a UserType to map the XML data (saved as Type XML) into beans using XMLBeans. This works perfectly fine.

When it comes time to save the data I'm getting conversion errors (char to xml) thrown by PostgreSQL.

I've overridden the nullSafeSet function and have tried multiple things:
1) Using PostgreSQL's functions to convert strings to XML:
Code:
XMLPARSE( DOCUMENT  "xml goes here")


2) Tried to use the SQLXML object:
Code:
           XmlObject loObject = (XmlObject)value;
           
           Connection conn = statement.getConnection();
           SQLXML article = null;
           
           try {
              article = conn.createSQLXML();
           }catch(SQLFeatureNotSupportedException sfnsE) {
              sfnsE.printStackTrace();
              throw new HibernateException(sfnsE.getMessage());
           }catch(SQLException sqlE) {
              sqlE.printStackTrace();
              throw new HibernateException(sqlE.getMessage());
           }
              
           DOMResult dom = (DOMResult)article.setResult(DOMResult.class);
           dom.setNode(loObject.getDomNode()); // doc is instance of org.w3c.dom.Document

           statement.setSQLXML(index, article);


Both with no luck.

Has anybody come across this and found a good solution to save PostgreSQL XML Type data?

Thanks.[/code]


Top
 Profile  
 
 Post subject: [solved]
PostPosted: Tue Feb 03, 2009 2:55 pm 
Newbie

Joined: Tue Feb 03, 2009 10:24 am
Posts: 2
[solved - thought I'd post for others]

Code:

Inside:
public void nullSafeSet(PreparedStatement statement, Object value, int index)

........
XmlObject loXmlObject = (XmlObject)value;
String lsXmlValue = getAsString(loXmlObject);

PGobject pgObject = new PGobject();
pgObject.setType("xml");
pgObject.setValue(lsXmlValue);
statement.setObject(index, pgObject);

.............


Top
 Profile  
 
 Post subject: Re: PostgreSQL XML Type mapping (saving XML)
PostPosted: Mon Nov 03, 2014 6:03 am 
Newbie

Joined: Mon Nov 03, 2014 5:56 am
Posts: 2
Can you add the code of User Type that you created?


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

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.