persistence@glassfish.java.net

Re: using composition with JPA

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Mon, 23 Jul 2007 15:18:05 -0700

Will using either inheritance or a ToOne relationship instead solve your problem?

thanks,
-marina

sud wrote:
> If I have a composition type relationship between two classes (Class A
> and Class B where Class B is composed of Class A). Both Class A and
> Class B are entities and have @Entity annotation on them.
>
> When object of type Class B is created it's instance variable classA is
> initialized as well. This instance variable of type Class A should be a
> snapshot of the object and must be persisted in the Class B table. How
> can I achieve this. Here is my Class B
>
> @Entity
> Class B {
>
> A a;
> .....
> ....
> }
>
> As it is now only the id field in Class A is persisted in the Class B
> table. I cannot used the @Embedded annotation on A because A already has
> an @Entity annotation as it is required in the domain.
>
> I'd appreciate any pointers.
>
> Thanks
> -sud
>
>
>
> ------------------------------------------------------------------------
> Get the free Yahoo! toolbar
> <http://us.rd.yahoo.com/evt=48226/*http://new.toolbar.yahoo.com/toolbar/features/norton/index.php>
> and rest assured with the added security of spyware protection.