Skip to main content

"shared" Entity beans in different applications?

2 replies [Last post]
Anonymous

Folks;

in the midst of slowly migrating to Java EE, I'm still struggling with,
well, rather basic EJB3 related questions, hope asking them around here is
not all that stupid (sorry if it is, after all):

So far, using Spring in webapps, I used to build a shared "-api" .jar
project to contain most of my domain classes along with DAO interfaces
allowing to get them off some backend storage implementation. Having each
relevant applications depending upon these "-api" .jars, coding seemed
rather easy.

Switching to EJB3 however, I tried to do the same thing in a rather simple way:

- Built a "-api" .jar containing EJB3 entity beans representing my domain
classes as stored in the backend DB along with ...FacadeRemote interfaces.

- Created a set of EJB3 modules, one ("-service") to implement the
...FacadeRemote interfaces, and one ("-consumer"), both depending upon the
"-api" one.

- Created a stateless session bean in "-consumer" doing nothing more than
trying to make use of the ...FacadeRemote interface in order to fetch an
entity bean off the backend. Exposed this bean as a @WebService.

Using the GFv2 web administration console's Web Service Tester for the
@WebService in "-consumer", then, makes the whole mess fail dumping an error
like this:

[...]
Caused by: javax.ejb.TransactionRolledbackLocalException: Exception thrown
from bean; nested exception is: java.lang.IllegalArgumentException: Unknown
entity
bean class: class foo.entities.MyEntity, please verify that this class has
been marked with the @Entity annotation.
[...]

Tried this so far in various combinations, each and every time again
stumbling across errors like this (or others - having a ...FacadeRemote
implementation in a different "project" than the Entity itself while trying
to access a NamedQuery making the EntityManager complain about the
NamedQuery being unknown).

So, from that point of view: Is there a way of creating a module structure
like this in EJB3, having entity beans known to a set of other modules
depending upon them? I am not sure whether or not this question is simple,
but after all it seems most of the tutorials (including the EJB3 books on my
shelf) seem to be limited to different EJB modules distributed at the very
least in a common .ear application which is not the case in my environment
however.

Help, anyone? :)

TIA and all the best,
Kristian

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Marina Vatkina

Kristian,

Do you deploy each module separately or package them together into an ear file?

While it's not as nice, it can be better if you make your -entities.jar
duplicated in each archive that you deploy (if you deploy and -ejb.jar as a
separate module, you'd need to unpack -entities.jar so that -ejb.jar contains
entity classes directly).

Regards,
-marina

Kristian Rink wrote:
> Folks;
>
> in the midst of slowly migrating to Java EE, I'm still struggling with,
> well, rather basic EJB3 related questions, hope asking them around here is
> not all that stupid (sorry if it is, after all):
>
> So far, using Spring in webapps, I used to build a shared "-api" .jar
> project to contain most of my domain classes along with DAO interfaces
> allowing to get them off some backend storage implementation. Having each
> relevant applications depending upon these "-api" .jars, coding seemed
> rather easy.
>
> Switching to EJB3 however, I tried to do the same thing in a rather simple way:
>
> - Built a "-api" .jar containing EJB3 entity beans representing my domain
> classes as stored in the backend DB along with ...FacadeRemote interfaces.
>
> - Created a set of EJB3 modules, one ("-service") to implement the
> ...FacadeRemote interfaces, and one ("-consumer"), both depending upon the
> "-api" one.
>
> - Created a stateless session bean in "-consumer" doing nothing more than
> trying to make use of the ...FacadeRemote interface in order to fetch an
> entity bean off the backend. Exposed this bean as a @WebService.
>
>
> Using the GFv2 web administration console's Web Service Tester for the
> @WebService in "-consumer", then, makes the whole mess fail dumping an error
> like this:
>
> [...]
> Caused by: javax.ejb.TransactionRolledbackLocalException: Exception thrown
> from bean; nested exception is: java.lang.IllegalArgumentException: Unknown
> entity
> bean class: class foo.entities.MyEntity, please verify that this class has
> been marked with the @Entity annotation.
> [...]
>
>
> Tried this so far in various combinations, each and every time again
> stumbling across errors like this (or others - having a ...FacadeRemote
> implementation in a different "project" than the Entity itself while trying
> to access a NamedQuery making the EntityManager complain about the
> NamedQuery being unknown).
>
> So, from that point of view: Is there a way of creating a module structure
> like this in EJB3, having entity beans known to a set of other modules
> depending upon them? I am not sure whether or not this question is simple,
> but after all it seems most of the tutorials (including the EJB3 books on my
> shelf) seem to be limited to different EJB modules distributed at the very
> least in a common .ear application which is not the case in my environment
> however.
>
> Help, anyone? :)
>
> TIA and all the best,
> Kristian
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

Kristian Rink

Hi Marina;

and first off, thanks a bunch for your feedback on that. :)

Marina Vatkina schrieb:
> Do you deploy each module separately or package them together into an
> ear file?

Best thing actually would be (in my opinion) to be capable of deploying each
module separately as this comes closest to the idea of "loose coupled"
architecture I have in mind. :)

> While it's not as nice, it can be better if you make your -entities.jar
> duplicated in each archive that you deploy (if you deploy and -ejb.jar
> as a separate module, you'd need to unpack -entities.jar so that
> -ejb.jar contains entity classes directly).

So maybe this is the problem... Right now I am using NetBeans IDE to do the
development, having -entities and -ejb two different EJB modules, and it
seems -ejb, depending upon -entities, indeed does include -entities.jar
rather than "just" the classes in -entities. Gonna look for a way around this...

Thanks a bunch, anyway, for your comments on that. :)
Cheers,
Kristian

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net