Discussions

EJB programming & troubleshooting: Design question - how to create a thread safe operation in state

  1. Hey, I have the following problem. I need to create a new EntityManagerFactory and rebind it to the JNDI: [code]EntityManagerFactory emf = new Ejb3Configuration().setProperty( "hibernate.connection.datasource", "java:/DefaultDS").setProperty( "hibernate.hbm2ddl.auto", "create").setProperty("hibernate.show_sql", "true") .addAnnotatedClass(Hotel.class).addAnnotatedClass(Room.class) .buildEntityManagerFactory(); new InitialContext().rebind("java:/sample3", emf);[/code] I need that this code will be thread safe, because i dont want that 2 threads simultaneously will create the same EntityManagerFactory . How can I do it in a stateless? Thank you
  2. Do it in a startup class... Any particular reason to put it in stateless sb
  3. I didn't understand what do you want ! Do you want 1 instance of EntityManagerFactory only that another place(method) it'll use it? Remember, about stateless's life cycle, wherever you must analyze what do you need. I advise you for each method you need use it, you to create a new instance of EntityManagerFactory, because the objetc will living while the method to be living. :)