0

I was needing to use JPA in standalone application, so I've found the example http://tomee.apache.org/latest/examples/jpa-hibernate.html as starter.

They create EJB Context via

final Context context = EJBContainer.createEJBContainer(p).getContext();

Then there's a log line:

INFO - Enterprise application "/Users/dblevins/examples/jpa-hibernate" loaded

You need to know that application name to wizard out the search string for lookup:

context.lookup("java:global/jpa-hibernate/Movies");

What makes me worry that I've found out no information on where those 'jpa-hibernate' part comes from. It either comes from artifact id, or, even worse, from the current directory name, which makes the code using it terribly dependend on context, that the developer doesn't control.

I've totally find to google out how to specify that application name so that I could use lookup that will work no matter who invokes my code and where it is copied.

How can I configure this application name?

9ilsdx 9rvj 0lo
  • 7,955
  • 10
  • 38
  • 77
  • What do you mean by standalone application? The example shown seems to be an ejb-jar deployed to TomEE application server. Possible duplicate of https://stackoverflow.com/questions/3431357/how-can-i-config-module-and-application-name-for-jndi-lookups Does this help? – Jochen Reinhardt May 15 '19 at 11:32
  • @JochenReinhardt the example is a fragment of JUnit test, so definitely not deployed to any container... – 9ilsdx 9rvj 0lo May 15 '19 at 12:28
  • @JochenReinhardt standalone = run as normal java application, with java command or IDE or with manifest of executable jar.... Definitely no EAR or WAR exists in my code. – 9ilsdx 9rvj 0lo May 15 '19 at 12:30
  • Sorry - did not notice the Embedded EJB Container. It allows to run EJBs outside a java-ee container. But it also supports `` in `ejb-jar.xml`. See also https://docs.oracle.com/javaee/6/tutorial/doc/gkcrr.html – Jochen Reinhardt May 15 '19 at 13:29
  • @JochenReinhardt yeah, something like https://developer.jboss.org/thread/165085 , hard to find out if you don't know where to look :o, thanks a lot! – 9ilsdx 9rvj 0lo May 15 '19 at 15:20
  • So it's working as expected now? Would you mind accepting my answer, that basically sums up the info's from the comment. This way, the answer might help others, too. – Jochen Reinhardt May 16 '19 at 07:27

1 Answers1

1

The Embedded EJB container used in this unit test example allows to run EJBs outside a Java EE container. A good introduction/tutorial can be found here: https://docs.oracle.com/javaee/7/tutorial/ejb-embedded002.htm

It supports the same configuration files as regular EJB-jars, namely it supports the ejb-jar.xml configuration file (the module deployment descriptor). It is possible to configure the module name there, e.g.

<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"  
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"  
         version="3.1">  
    <module-name>myapp</module-name>  
</ejb-jar>  

This file needs to go into the jar's META-INF directory.

Jochen Reinhardt
  • 833
  • 5
  • 14