-->
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.  [ 7 posts ] 
Author Message
 Post subject: Getting the HQL query result in XML format
PostPosted: Thu Feb 26, 2009 12:58 pm 
Newbie

Joined: Thu Feb 26, 2009 12:49 pm
Posts: 4
Hello,

Hibernate version: 3.2.1

Name and version of the database you are using: SQL Server 2000

I am trying to get the hql result as XML. I use XML mapping. Any help is appreciated.

Thanks,
Viz


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2009 2:22 pm 
Senior
Senior

Joined: Tue Aug 01, 2006 9:24 pm
Posts: 120
I might not understand you correctly, but hibernate does not serialize/convert to xml. It will always return your pojo objects. You need to do this manually or use some kind of serializing library.

You can try these.
Castor - www.castor.org
XStream - xstream.codehaus.org
JAXB - jaxb.dev.java.ne

_________________
Please rate my replies as I need points for all of my questions also.


Top
 Profile  
 
 Post subject: Thank You.
PostPosted: Fri Feb 27, 2009 10:43 am 
Newbie

Joined: Thu Feb 26, 2009 12:49 pm
Posts: 4
Thanks, ethnarch. If I have to it myself, can you tell me how do I get meta data information about query. I mean what entities and what columns are selected.

Viz


Top
 Profile  
 
 Post subject: Thank You.
PostPosted: Fri Feb 27, 2009 10:44 am 
Newbie

Joined: Thu Feb 26, 2009 12:49 pm
Posts: 4
Thanks, ethnarch. If I have to it myself, can you tell me how do I get meta data information about query. I mean what entities and what columns are selected. (I wanted to build result in XML dynamically).

Viz


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2009 12:44 pm 
Senior
Senior

Joined: Tue Aug 01, 2006 9:24 pm
Posts: 120
What are you returning from your hql query raw objects or actual Pojo classes.

If you are using pojo classes. Using the xml or annotations you can use reflection to get at what the class is and then find all it's defined fields etc.

I have a project which does this already, although it's not quite finished yet but feel free to take the source code. The other catch with it is that it only works with annotations.

proselyte.sourceforge.net

_________________
Please rate my replies as I need points for all of my questions also.


Top
 Profile  
 
 Post subject: Metadata
PostPosted: Fri Feb 27, 2009 3:22 pm 
Newbie

Joined: Thu Feb 26, 2009 12:49 pm
Posts: 4
I am retrieving set of objects using eager fetch and I might not be retrieving all the objects associated with the selected object. So I have to know the objects that are retrieved in the query and also I have to know all the objects actually associated with the object. And I have to generate the XML for the objects that are selected in the query. Is it similar to what you did. Any help is appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2009 3:36 pm 
Senior
Senior

Joined: Tue Aug 01, 2006 9:24 pm
Posts: 120
Ok so say you have mapped classes A, B and C such that in the simplest scenario we have a mapped tree that looks like this.

A{
int pkId

@OneToOne
int FKBId
}
B{
int pkId

@OneToOne
int FKCId
}
C{
int pkId

}

So C is mapped in B and B is mapped in A as OneToMany

Sometimes your queries might result in these classes being return as
A.B

Where there is no C mapped to B.

Is this correct?

This is pretty normal and I believe XStream and Castor can handle these issues. If you always know what the top of the mapped hierarchy is meaning you are always loading in Class A then this would probably be the best route to go because these are well documented and stable libraries.

I can't really give you any examples on how to use them but if you go to the sites the documentation will be there.

_________________
Please rate my replies as I need points for all of my questions also.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.