[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - java.io.NotSerializableException: org.jboss.ejb.plugins.cmp.

fla83tn do-not-reply at jboss.com
Sun Aug 6 09:12:57 EDT 2006


Hi, 
I'm trying to learn to manage relationship between two entity beans and the situation is the following:

I have a Customer that purchase orders, so an order have its own table Orders that is composed by 3 fields: id, customer and  product purchased. 
Thus, given some Customer  I want to know all its purchased orders. 
(Remark: Instead of Order I renamed it as OrderItem beacuse of it is a reserved word in mysql...)

So, I do the following to get the related orders:

  |  Collection coll = client.getOrders(dto);
  |             if (coll!=null){
  |                 Iterator it = coll.iterator();
  |                 while (it.hasNext()) {
  |                     System.out.println(">>>> ORDER FOUND! ");
  |                 }
  |             }else{
  |                 System.out.println("<<<< ERROR RETRIEVING ORDERS..! >>>>>> ");
  |             }
  | 

But then I get this error:


  | java.lang.reflect.UndeclaredThrowableException
  | 	at $Proxy1.getOrders(Unknown Source)
  | 	at test.SessionFacadeTestClient.getOrders(SessionFacadeTestClient.java:290)
  | 	at test.SessionFacadeTestClient.main(SessionFacadeTestClient.java:371)
  | Caused by: java.io.NotSerializableException: org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet
  | 	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
  | 	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:291)
  | 

My ejb-jar is the following:

  | <entity>
  |       <ejb-name>Customer</ejb-name>
  |       <local-home>untitled2.entity.customer.CustomerHome</local-home>
  |       <local>untitled2.entity.customer.Customer</local>
  |       <ejb-class>untitled2.entity.customer.CustomerBean</ejb-class>
  |       <persistence-type>Container</persistence-type>
  |       <prim-key-class>untitled2.entity.customer.CustomerPK</prim-key-class>
  |       <reentrant>False</reentrant>
  |       <cmp-version>2.x</cmp-version>
  |       <abstract-schema-name>Customer</abstract-schema-name>
  |       <cmp-field>
  |         <field-name>id</field-name>
  |       </cmp-field>
  |       <cmp-field>
  |         <field-name>name</field-name>
  |       </cmp-field>
  | </entity>
  | <entity>
  |       <ejb-name>OrderItem</ejb-name>
  |       <local-home>untitled2.entity.order.OrderItemHome</local-home>
  |       <local>untitled2.entity.order.OrderItem</local>
  |       <ejb-class>untitled2.entity.order.OrderItemBean</ejb-class>
  |       <persistence-type>Container</persistence-type>
  |       <prim-key-class>untitled2.entity.order.OrderItemPK</prim-key-class>
  |       <reentrant>False</reentrant>
  |       <cmp-version>2.x</cmp-version>
  |       <abstract-schema-name>OrderItem</abstract-schema-name>
  |       <cmp-field>
  |         <field-name>id</field-name>
  |       </cmp-field>
  |       <cmp-field>
  |         <field-name>product</field-name>
  |       </cmp-field>
  |       <ejb-local-ref>
  |         <ejb-ref-name>ejb/Customer</ejb-ref-name>
  |         <ejb-ref-type>Entity</ejb-ref-type>
  |         <local-home>untitled2.entity.customer.CustomerHome</local-home>
  |         <local>untitled2.entity.customer.Customer</local>
  |         <ejb-link>Customer</ejb-link>
  |       </ejb-local-ref>
  |  </entity>
  | 

The jbosscmp-jdbc.xml is:


  | <jbosscmp-jdbc>
  |   <defaults>
  |     <datasource>java:/examplesDB</datasource>
  |     <datasource-mapping>mySQL</datasource-mapping>
  |     <create-table>true</create-table>
  |     <remove-table>false</remove-table>
  |     <read-only>false</read-only>
  |     <pk-constraint>true</pk-constraint>
  |     <read-ahead>
  |       <strategy>on-load</strategy>
  |       <page-size>15</page-size>
  |       <eager-load-group>*</eager-load-group>
  |     </read-ahead>
  |   </defaults>
  |   <enterprise-beans>
  |     <entity>
  |       <ejb-name>Customer</ejb-name>
  |       <table-name>customer</table-name>
  |       <cmp-field>
  |         <field-name>id</field-name>
  |         <column-name>id</column-name>
  |       </cmp-field>
  |       <cmp-field>
  |         <field-name>name</field-name>
  |         <column-name>name</column-name>
  |       </cmp-field>
  |     </entity>
  |     <entity>
  |       <ejb-name>OrderItem</ejb-name>
  |       <table-name>orders</table-name>
  |       <cmp-field>
  |         <field-name>id</field-name>
  |         <column-name>id</column-name>
  |       </cmp-field>
  |       <cmp-field>
  |         <field-name>product</field-name>
  |         <column-name>product</column-name>
  |       </cmp-field>
  |     </entity>
  |   </enterprise-beans>
  |   <relationships>
  |     <ejb-relation>
  |       <ejb-relation-name>Customer-orders</ejb-relation-name>
  |       <foreign-key-mapping />
  |       <ejb-relationship-role>
  |         <ejb-relationship-role-name>Customer-owns-orders</ejb-relationship-role-name>
  |         <key-fields>
  |           <key-field>
  |             <field-name>id</field-name>
  |             <column-name>customer</column-name>
  |           </key-field>
  |         </key-fields>
  |       </ejb-relationship-role>
  |       <ejb-relationship-role>
  |         <ejb-relationship-role-name>orders-belongs-to-customer</ejb-relationship-role-name>
  |         <key-fields />
  |       </ejb-relationship-role>
  |     </ejb-relation>
  |   </relationships>
  | </jbosscmp-jdbc>
  | 

Obviously, I set up the mysql-ds.xml properly beacause the tables are created correctly!
Any ideas?

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

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



More information about the jboss-user mailing list