[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Generate XML from an entity

poyge394 do-not-reply at jboss.com
Tue May 29 09:40:09 EDT 2007


Hi, 
In my application i generate an xml file from entity beans,
before i run 
manger.persist(entity);

my generated xml looks like:


  | <rollingstock>
  |   <rollingstockId>0</rollingstockId>
  |   <route>Stockholm</route>
  |   <nextRoute>Uppsala</nextRoute>
  |   <schedule>
  |     <id>0</id>
  |     <destination>destination</destination>
  |   </schedule>
  |   <vehicles>
  |     <vehicle>
  |       <id>0</id>
  |       <vehicleId>1412</vehicleId>
  |       <litt>litt</litt>
  |       <ticketId>1412</ticketId>
  |       <vehicleType>vehicleType</vehicleType>
  |       <weight>
  |         <weight>78.0</weight>
  |       </weight>
  |       <dynamicWeight>
  |         <weight>78.0</weight>
  |       </dynamicWeight>
  |       <brakeWeight>
  |         <weight>110.0</weight>
  |       </brakeWeight>
  |       <length>
  |         <length>155.3</length>
  |         <unit>M</unit>
  |       </length>
  |       <nrOfAxles>4</nrOfAxles>
  |       <speed>
  |         <speed>160.0</speed>
  |         <unit>s</unit>
  |       </speed>
  |       <service>PULLING</service>
  |       <canDoorsBeLocked>true</canDoorsBeLocked>
  |       <phoneNumbers>
  |         <phonenumber>
  |           <id>0</id>
  |           <location>Ahytt</location>
  |           <number>0148782373</number>
  |         </phonenumber>
  |       </phoneNumbers>
  |       <passengerCarConfiguration>
  |         <id>0</id>
  |         <class1>10</class1>
  |         <class2>10</class2>
  |         <couchette>5</couchette>
  |         <compartments>10</compartments>
  |       </passengerCarConfiguration>
  |       <comments>
  |         <comment>
  |           <id>0</id>
  |           <comment>Comment about this vihicle</comment>
  |         </comment>
  |       </comments>
  |       <nextAssignment>9010</nextAssignment>
  |       <schedule reference="../../../schedule"/>
  |       <nextSchedule reference="../../../schedule"/>
  |       <positionInTrainAssembly>0</positionInTrainAssembly>
  |     </vehicle>
  |   </vehicles>
  | </rollingstock>
  | 

After:


  | <rollingstock>
  |   <rollingstockId>4200</rollingstockId>
  |   <route>Stockholm</route>
  |   <nextRoute>Uppsala</nextRoute>
  |   <schedule>
  |     <id>4200</id>
  |     <destination>destination</destination>
  |   </schedule>
  |   <vehicles class="org.hibernate.collection.PersistentBag">
  |     <bag>
  |       <vehicle>
  |         <id>3700</id>
  |         <vehicleId>1412</vehicleId>
  |         <litt>litt</litt>
  |         <ticketId>1412</ticketId>
  |         <vehicleType>vehicleType</vehicleType>
  |         <weight>
  |           <weight>78.0</weight>
  |         </weight>
  |         <dynamicWeight>
  |           <weight>78.0</weight>
  |         </dynamicWeight>
  |         <brakeWeight>
  |           <weight>110.0</weight>
  |         </brakeWeight>
  |         <length>
  |           <length>155.3</length>
  |           <unit>M</unit>
  |         </length>
  |         <nrOfAxles>4</nrOfAxles>
  |         <speed>
  |           <speed>160.0</speed>
  |           <unit>s</unit>
  |         </speed>
  |         <service>PULLING</service>
  |         <canDoorsBeLocked>true</canDoorsBeLocked>
  |         <phoneNumbers class="org.hibernate.collection.PersistentSet">
  |           <set>
  |             <phonenumber>
  |               <id>3600</id>
  |               <location>Ahytt</location>
  |               <number>0148782373</number>
  |             </phonenumber>
  |           </set>
  |           <initialized>true</initialized>
  |           <cachedSize>-1</cachedSize>
  |           <dirty>false</dirty>
  |           <storedSnapshot class="map">
  |             <entry>
  |               <phonenumber reference="../../../set/phonenumber"/>
  |               <phonenumber reference="../../../set/phonenumber"/>
  |             </entry>
  |           </storedSnapshot>
  |         </phoneNumbers>
  |         <passengerCarConfiguration>
  |           <id>3600</id>
  |           <class1>10</class1>
  |           <class2>10</class2>
  |           <couchette>5</couchette>
  |           <compartments>10</compartments>
  |         </passengerCarConfiguration>
  |         <comments class="org.hibernate.collection.PersistentSet">
  |           <set>
  |             <comment>
  |               <id>3600</id>
  |               <comment>Comment about this vihicle</comment>
  |             </comment>
  |           </set>
  |           <initialized>true</initialized>
  |           <cachedSize>-1</cachedSize>
  |           <dirty>false</dirty>
  |           <storedSnapshot class="map">
  |             <entry>
  |               <comment reference="../../../set/comment"/>
  |               <comment reference="../../../set/comment"/>
  |             </entry>
  |           </storedSnapshot>
  |         </comments>
  |         <nextAssignment>9010</nextAssignment>
  |         <schedule reference="../../../../schedule"/>
  |         <nextSchedule reference="../../../../schedule"/>
  |         <positionInTrainAssembly>0</positionInTrainAssembly>
  |       </vehicle>
  |     </bag>
  |     <initialized>true</initialized>
  |     <cachedSize>-1</cachedSize>
  |     <dirty>false</dirty>
  |     <storedSnapshot class="list">
  |       <vehicle reference="../../bag/vehicle"/>
  |     </storedSnapshot>
  |   </vehicles>
  | </rollingstock>
  | 
  | 

as you see hibernate add hibernate specific information to the POJO as:

  |     <initialized>true</initialized>
  |     <cachedSize>-1</cachedSize>
  |     <dirty>false</dirty>
  |     <storedSnapshot class="list">
  |       <vehicle reference="../../bag/vehicle"/>
  |     </storedSnapshot>
  | 
is it possible to get an xml as it look like before the manager.persist call.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4049334#4049334

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4049334



More information about the jboss-user mailing list