The point is that I can have only objects namely order and customer. The
order object is being loaded through hibernate and the customer object is
being loaded through lazy loading while loading the order object. So I will
only have the order object with a reference to the customer object and this
is what I can pass to the marshaller.

Is there not any way to create the xml of the parent while creating the
child xml ? that will be the ideal solution to my case.

I want the xml equivalent of something like (other details not show in the
xml below) -

<orderTb>
    <customer>
        <order.getCustomer().getCustomerId()/>
        <order.getCustomer().getCustomerName()/>
    </customer>
</orderTb>


Regds
Sundeep


On Tue, Aug 26, 2008 at 7:16 PM, karthik govindaswamy <
[EMAIL PROTECTED]> wrote:

>
>
>
>> ie. one customer can have multiple order is what you are looking at then
>> the structure should be  something like this...when you have multiple
>> records...
>> <orderTb>
>>    <customer>
>>
>          <customer-id>1</customer-id>
>         <customer-name>xxxxxx</customer-name>
>           <order-id>ORD123</order-id>
>           <order-id>ORD1234</order-id>
>    <customer>
>    <customer>          <customer-id>2</customer-id>
>         <customer-name>yyyyyy</customer-name>
>           <order-id>ORD111</order-id>
>           <order-id>ORD1234</order-id>
>    <customer>
> </orderTb>
> Does this structure solve your logic. In that case you wil have three class
> orderTB
> Customer
> Order-Id
>
> class orderTB{
> ArrayList CustomerList;
> Add get and set method.
> }
> Class Customer{
> String customer-id;
> String CustomerName;
> ArrayList Order-IdList;
>  Add get and set method.
> }
> Class order-Id{
> String order-idValue;
>  Add get and set method.
> }
>
> The binding xml will be.
>
> <
> binding value-style="attribute">
> <mapping class="orderTB" name="orderTB"  >
>   <collection  field="CustomerList" usage="optional">
>       <structure  name="Customer"  map-as="Customer" usage="optional"/>
>  </collection>
> </mapping>
>
> <
> mapping type-name="Customer" class="Customer" abstract="true">
>
> <
> value style="element" name="customer-id" field="customer-id" usage=
> "optional"/>
>
>  <value style="element" name="CustomerName" field="customer-id" usage=
> "optional"/>
>
> <collection  field="Order-IdList" usage="optional">
>       <structure  name="Order-Id"  map-as="Order-Id" usage="optional"/>
>  </collection>
> </mapping>
>
>
>
> <mapping type-name="Order-Id" class="Order-Id" abstract="true">
>
>  <value style="element" name="Order-Id" field="order-idValue" usage=
> "optional"/>
>
> </mapping>
> </binding>
>
> and your main class for marshalling would not change. Let me know how it
> goes.
>
>
> Thanks
>
> Karthik
>
>
> The point is, there will be only one customer tag associated to order since
> customer is the parent and has a one-to-many relation with order.
>
>   Regds
>> Sundeep
>>
>>
>> On Tue, Aug 26, 2008 at 6:48 PM, karthik govindaswamy <
>> [EMAIL PROTECTED]> wrote:
>>
>>>  you havent said how the multiple mapping is going to be..
>>> What would be the xml strucuture look like if you have multiple customers
>>> and orders?? i guess this is the structure you want...
>>>
>>> <orderTb>
>>>   <order-id ordernum = "ORD123>
>>>    <customer>
>>>        <customer-id>1</customer-id>
>>>        <customername>xxxxxx</customername>
>>>    <customer>
>>>     <customer>
>>>        <customer-id>2</customer-id>
>>>        <customername>xxxxxx</customername>
>>>     <customer>
>>>   </order-id>
>>> </orderTb>
>>>
>>> or
>>>
>>> <orderTb>
>>>   <customer>
>>>       <order-id>ORD123</order-id>
>>>      <customer-id>1</customer-id>
>>>      <customername>xxxxxx</customername>
>>>   <customer>
>>>   <customer>
>>>      <order-id>ORD123</order-id>
>>>     <customer-id>2</customer-id>
>>>     <customername>xxxxxx</customername>
>>>   <customer>
>>> </orderTb>
>>>
>>> correct me if i misunderstood your reqt..
>>>
>>>   On Tue, Aug 26, 2008 at 9:02 AM, Sundeep Malali <
>>> [EMAIL PROTECTED]> wrote:
>>>
>>>> Something like this -
>>>>
>>>> <orderTb>
>>>>   <order-id>ORD123</order-id>
>>>>   <customer>
>>>>     <customer-id>1</customer-id>
>>>>     <customername>xxxxxx</customername>
>>>>   <customer>
>>>> </orderTb>
>>>>
>>>> Regds
>>>> Sundeep
>>>>
>>>>
>>>> On Tue, Aug 26, 2008 at 6:06 PM, karthik govindaswamy <
>>>> [EMAIL PROTECTED]> wrote:
>>>>
>>>>> what is the resultant xml structure that you are trying to
>>>>> achieve,,,!!!
>>>>>
>>>>>   On Tue, Aug 26, 2008 at 8:16 AM, Sundeep Malali <
>>>>> [EMAIL PROTECTED]> wrote:
>>>>>
>>>>>>   Hi
>>>>>>
>>>>>> I have just started using JIBX and have a query.
>>>>>>
>>>>>> I have 2 classes which share a parent-child one-to-many relation. For
>>>>>> displaying purposes, I get a list of all children (in general, not 
>>>>>> specific
>>>>>> to a parent) and also the parent info for each child. Now I pass each 
>>>>>> child
>>>>>> object to convert to xml. But while converting the child object, I also 
>>>>>> want
>>>>>> the parent to be converted to xml.
>>>>>>
>>>>>> The binding info is given below :
>>>>>>
>>>>>> *Child object binding:*
>>>>>> <mapping class="com.redbus.homedelivery.orm.OrderTb" name="orderTb">
>>>>>>     <value style="element" name="order-id" field="orderId"/>
>>>>>>     <structure field="customer"/> - This is the parent object
>>>>>> </mapping>
>>>>>>
>>>>>> *Parent object binding*:
>>>>>> <mapping class="com.redbus.homedelivery.orm.Customer" name="customer">
>>>>>>     <value style="element" name="customer-id" field="customerId"/>
>>>>>>     <collection field="orders"
>>>>>> item-type="com.redbus.homedelivery.orm.OrderTb"/> - This is the child
>>>>>> object.
>>>>>> </mapping>
>>>>>>
>>>>>> While using this binding, I get a null pointer exception in the parent
>>>>>> object.
>>>>>>
>>>>>> ----------------------------------------------------------------------------------------------------------------
>>>>>> Caused by: java.lang.NullPointerException
>>>>>>     at
>>>>>> com.redbus.homedelivery.orm.Customer.JiBX_HomeDelivery_jibx_binding_binding_marshal_1_0(Customer.java)
>>>>>>     at
>>>>>> com.redbus.homedelivery.orm.JiBX_HomeDelivery_jibx_binding_bindingCustomer_access.marshal()
>>>>>>     at
>>>>>> com.redbus.homedelivery.orm.OrderTb.JiBX_HomeDelivery_jibx_binding_binding_marshal_1_0(OrderTb.java)
>>>>>>     at
>>>>>> com.redbus.homedelivery.orm.JiBX_HomeDelivery_jibx_binding_bindingOrderTb_access.marshal()
>>>>>>     at com.redbus.homedelivery.orm.OrderTb.marshal(OrderTb.java)
>>>>>>     at
>>>>>> org.jibx.runtime.impl.MarshallingContext.marshalRoot(MarshallingContext.java:1041)
>>>>>>     at
>>>>>> org.jibx.runtime.impl.MarshallingContext.marshalDocument(MarshallingContext.java:1111)
>>>>>>     at
>>>>>> com.redbus.homedelivery.common.XMLUtils.getXML(XMLUtils.java:27)
>>>>>>
>>>>>> ----------------------------------------------------------------------------------------------------------------
>>>>>>
>>>>>> The code to perform the conversion is given below :
>>>>>>
>>>>>>     public static String getXML(Object obj) {
>>>>>>         String xml = "";
>>>>>>         try {
>>>>>>             IBindingFactory bfact;
>>>>>>             bfact = BindingDirectory.getFactory(obj.getClass());
>>>>>>             // marshal root object back out to document in memory
>>>>>>             IMarshallingContext mctx =
>>>>>> bfact.createMarshallingContext();
>>>>>>             mctx.setIndent(2);
>>>>>>             ByteArrayOutputStream bos = new ByteArrayOutputStream();
>>>>>>             mctx.marshalDocument(obj, "UTF-8", null, bos);
>>>>>>             xml = new String(bos.toByteArray(),"UTF-8");
>>>>>>         } catch (Exception e) {
>>>>>>             throw new MarshallingException("Unable to marshal from the
>>>>>> object " + obj, e);
>>>>>>         }
>>>>>>         return xml;
>>>>>>     }
>>>>>>
>>>>>> I pass the child object to this method and want the parent to be also
>>>>>> included in the final xml. The child object has the parent reference 
>>>>>> loaded
>>>>>> properly.
>>>>>>
>>>>>> Any help is greatly appreciated.
>>>>>>
>>>>>> Regds
>>>>>> Sundeep
>>>>>>
>>>>>>
>>>>>>
>>>>>> -------------------------------------------------------------------------
>>>>>> This SF.Net email is sponsored by the Moblin Your Move Developer's
>>>>>> challenge
>>>>>> Build the coolest Linux based applications with Moblin SDK & win great
>>>>>> prizes
>>>>>> Grand prize is a trip for two to an Open Source event anywhere in the
>>>>>> world
>>>>>> http://moblin-contest.org/redirect.php?banner_id=100&url=/
>>>>>> _______________________________________________
>>>>>> jibx-users mailing list
>>>>>> [email protected]
>>>>>> https://lists.sourceforge.net/lists/listinfo/jibx-users
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> -------------------------------------------------------------------------
>>>>> This SF.Net email is sponsored by the Moblin Your Move Developer's
>>>>> challenge
>>>>> Build the coolest Linux based applications with Moblin SDK & win great
>>>>> prizes
>>>>> Grand prize is a trip for two to an Open Source event anywhere in the
>>>>> world
>>>>> http://moblin-contest.org/redirect.php?banner_id=100&url=/
>>>>> _______________________________________________
>>>>> jibx-users mailing list
>>>>> [email protected]
>>>>> https://lists.sourceforge.net/lists/listinfo/jibx-users
>>>>>
>>>>>
>>>>
>>>>
>>>> -------------------------------------------------------------------------
>>>> This SF.Net email is sponsored by the Moblin Your Move Developer's
>>>> challenge
>>>> Build the coolest Linux based applications with Moblin SDK & win great
>>>> prizes
>>>> Grand prize is a trip for two to an Open Source event anywhere in the
>>>> world
>>>> http://moblin-contest.org/redirect.php?banner_id=100&url=/
>>>> _______________________________________________
>>>> jibx-users mailing list
>>>> [email protected]
>>>> https://lists.sourceforge.net/lists/listinfo/jibx-users
>>>>
>>>>
>>>
>>
>
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to