• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

mapping jms resource from jpa entity

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a jpa entity that has behavior, namely a method to send some message to a JMS queue. Since this entity is running inside a JEE container environment, the JMS specifics are being injected in the entity class itself, like this:

@Resource(name="jms/jmsQueue")
private Destination notifQueue;
@Resource(name="jms/jmsConnectionFactory")
private ConnectionFactory connectionFactory;

this entity has a method that uses the resources above, which gets called by the timeout method of a stateless EJB.

Since the resources are defined in the Entity and not in the calling EJB, other than using the [i]mappedName[/i] annotation attribute, where can I define a jndi mapping for these resources ? The ejb deployment descriptor ? persistence.xml ? There seems to be no place in any of them for this use case...

Can anyone help ?

Thanks
 
author & internet detective
Posts: 41855
904
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
John,
Why is your entity layer doing this? It seems to me that you should have a session bean which calls the entities and puts the message on the queue. While JPA is Java code and can in theory do anything, it is an odd layering for an architecture to call JMS.
 
Jonh Smith
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jeanne. Thanks for answering.

I don't want to get too deep into a design debate here, but the way I see it, entities are just Objects that happen to contain some persistence state. They don't have to be dumb data containers that have behavior attached to them via some external logic, which in my view represents a DAO pattern that tends to be more aligned with a procedural rather than an OOP approach, made unnecessary by the JPA standardization. For multiple reasons, I tend to rely on DTOs in any case to expose the model view outside the container, so no inner logic is exposed anyway.

But even assuming that I'm completely wrong :), i've begun to doubt, after looking at the specs in more detail, that resource injection in entities, other than persistence context related, is possible at all, so I'm considering using the explicit jndi look up technique instead, coupled with some mechanism that allows the deployer to configure the actual jndi name of the JMS destination and factory looked up. E.g. via environment properties in the deployment descriptor, that are explicitly provided in the entity's constructor and setter methods... haven't figured out the details yet.

In my view, the apparent impossibility to jndi-map resources used in jpa entities in a JEE environment is a spec limitation, not a design strategy, but I may be missing something really obvious, so anyone please feel free to correct me about this impossibility.

Thanks

 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic