[jboss-user] [EJB 3.0] - Re: Problem with containment interacting with inheritance?

knaveofhearts do-not-reply at jboss.com
Sat Jul 15 15:19:42 EDT 2006


I have worked on simplifying my problem, resulting in the following question--could someone please tell me how to, or have a code example of the annotations to configure combining inheritance with a one-to-many relationship among entities (i.e., A is the superclass of B. B contains a Collection of C objects) or for that matter a one-to-one (B contains an C) or many-to-many relationship? At this point, I am not picky about whether the relationship is uni- or bidirectional or about the inheritance strategy.

As an trial, I first converted exercise 7.1 from the workbook in the Burke & Monson-Haefel book, so that the entities run in a container. Client1 exercises a one-to-one unidirectional relationship between Customer and Address; Client2, a one-to-many unidirectional relationship between Customer and Phone. The Admin stateless session EJB includes createCustomer(), findCustomer(), and updateCustomer() methods implemented in the obvious way.  In either case, a detached instance of the Customer class is created, a field (address or list of phone numbers) is added to it while detached, and then admin.update() called to do a merge. The new Client1 and Client2 produce the correct results after the conversion.

Then I created a "Base" entity and made Customer extend Base using the JOINED strategy. Base contains an id field, with a getId() method annotated with "Id" and also setId(). I eliminated the id field from the Customer class.  This breaks both Client1 and Client2 in the sense that the Address and the Collection member variables in the Customer object remain null after the merge performed by updateCustomer() in Admin. This is true even within the updateCustomer method/transaction itself, so it does not help to set the fetch type to EAGER or to traverse the fields within the transaction explicitly.

I have so far been unable to find a working example of this common pattern, which is key to what I need to do.  Suggestions?


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

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



More information about the jboss-user mailing list