-->
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.  [ 5 posts ] 
Author Message
 Post subject: how to do mapping, where I just want a few columns
PostPosted: Mon Aug 22, 2005 1:27 pm 
Newbie

Joined: Wed Aug 03, 2005 2:23 pm
Posts: 4
Hibernate version: 3

Mapping documents:

Code:
<class name="Myclass" table="MyClass" node="MyClass">

  <id name="userid" column="UserID" node="UserID" type="java.lang.Integer">
    <generator class="identity"/>
  </id>
  <property name="Name" column="Name" node="Name" type="java.lang.Integer"  not-null="true" />
  <property name="somedate" column="someDate" node="someDate" type="java.util.Date"  not-null="true" />
</class>


Info

Here's what I'm trying to do. I have a table, that has 3 fields in it. In this case, I want to select all entries where "somedate" is equal to the date that I specify. I can do this just fine. And I want to turn the result into XML, which works just fine, too.

But what I really want, is that when the XML is output, each element in the result set does NOT have the "someDate" field in it, so that the XML might look somthing like this:

Code:
<MyClass>
  <userID>100</userID>
  <Name>Joe</Name>
</MyClass>
<MyClass>
  <userID>200</userID>
  <Name>Dan</Name>
</MyClass>

etc....

I'd rather not walk the result list, and remove each "someDate" element out of each "MyClass" element. I was hoping that there would be some way I could do this in the mapping file, so I wouldn't have to write post-processing code - so I could just get the list of Elements, and then output those Elements to an XML stream.

Is this possible?

Thanks,
-Dan.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 22, 2005 2:21 pm 
Newbie

Joined: Tue Aug 02, 2005 1:40 pm
Posts: 16
Location: US
Try to create a component of the fields you wish to display. Now you can always get the list of the component object which would only contain the fields that your require.

Usually components are used in a context where you have a too many columns. But looks like I would have applied for this perpous too.

_________________
Rajeshwar Rao

Please don't forget to give credit, if this posting helped to solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 22, 2005 3:04 pm 
Beginner
Beginner

Joined: Sun Jul 31, 2005 6:15 pm
Posts: 28
Can u explain how you generate the xml, is it a method you didn't write which take for argument your set, so you have to remove programatically the date in the result ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 22, 2005 3:34 pm 
Newbie

Joined: Wed Aug 03, 2005 2:23 pm
Posts: 4
Well, I do this:

Code:
Session dom4jSession = session.getSession(EntityMode.DOM4J);


then, I'd do something like this:

Code:
List theList = dom4jSession.createQuery("from MyClass myclass where myclass.someDate = ?).setDate(0, theDate).list()


This will give me a list of Dom4J Elements. Then I take these Elements, and add them to another Element, which resides inside of a Dom4j Document.

Then, once I've built up this Document, I create an OutputFormat, and an XMLWriter, and write it to a ByteArrayOutputStream. With the current mapping file as described, "someDate" would be a node in every "Myclass" Element. But I don't want to include that in the output. For the query, I need to do a "where" clause with the date, but I don't want it to see the date in the results.

So, the only way I can think of to do this, is to loop through all of the results, (which in this case are Dom4j Elements) and remove the "someDate" nodes, so when the XML gets flattened, the "someDate" fields don't show up.

I'd like to avoid this if I can. The code in here is just a sample to demonstrate what I'm trying to do. In reality, I want to omit a few columns from the XML output, but apply a "where" clause on them, to get the data desired.

Thanks,
-Dan.


Top
 Profile  
 
 Post subject: xslt
PostPosted: Mon Aug 22, 2005 5:29 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
And why do not try using XSLT to get rid of unwanted nodes?
Something like http://www.xml.com/pub/a/2000/06/07/transforming/

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.