[JNDI/Naming/Network] - Database JNDI call in EJB
by anacarda
Hi,
I am fairly new to JBoss, so I am possibly missing something.
I have a simple EJB, which just sets up a Connection to a JNDI datasource, then closes the connection.
try {
| Context loContext = (Context) new InitialContext().lookup("java:");
| DataSource loDataSource = (DataSource)loContext.lookup("Prophet_Data");
| Connection loConnection = loDataSource.getConnection();
| try {
| //
| } finally {
| if (!(loConnection == null)) {
| loConnection.close();
| }
| }
| } catch (Exception e) {
| e.printStackTrace();
| }
The JNDI Prophet_Data is defined within a seperate application, which is packaged into its own EAR (Which is Pentaho).
If I deploy this EJB jar to JBoss, then call the EJB within a simple jsp:
Properties props = new Properties();
| props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
|
| props.put(Context.PROVIDER_URL, "localhost:1099");
|
| Context ctx = new InitialContext(props);
|
| HelloHome home = (HelloHome)ctx.lookup("ejb/Hello");
| Hello bean = home.create();
| bean.simpleFunction();
| bean.remote();
| ctx.close();
When browsing to the jsp (eg: http://localhost:8080/testejb/testejb.jsp), it works fine.
However, If I modify the EJB code (and just add say, the initialisation of an integer eg:
int i = 0;
Then I redeploy the EJB jar... when I goto http://localhost:8080/testejb/testejb.jsp, it causes an exception to occur:
java.rmi.ServerException: EJBException:; nested exception is:
| javax.ejb.EJBException: Invalid invocation, check your deployment packaging, method=public abstract nz.co.mcpond.test.ejb.helloejb.Hello nz.co.mcpond.test.ejb.helloejb.HelloHome.create() throws javax.ejb.CreateException,java.rmi.RemoteException
| org.jboss.ejb.plugins.LogInterceptor.handleException(LogInterceptor.java:365)
| org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:136)
| org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyFactoryFinderInterceptor.java:107)
| org.jboss.ejb.SessionContainer.internalInvokeHome(SessionContainer.java:637)
| org.jboss.ejb.Container.invoke(Container.java:981)
| sun.reflect.GeneratedMethodAccessor402.invoke(Unknown Source)...
I can get around this by setting, CallByValue to true, however, reading http://wiki.jboss.org/wiki/Wiki.jsp?page=ClassLoadingConfiguration seems to suggest that this is a performance hit.
Am I doing something wrong? or not setting something correctly?
Is this because the JNDI datasource is not defined within my EJB jar? (ie: because it is defined within Pentaho.ear, does this mean that only that application can use the JNDI (without using CallByValue??)
Any help would be appreciated
Antonio Broughton
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4113222#4113222
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4113222
18 years, 4 months
[JBoss jBPM] - Re: Could not find datasource: java:/JbpmDS
by rodosa
Sorry! How can I do that?
| Context ctx = new InitialContext();
|
| Hashtable<String, String> env;
| env = new Hashtable<String, String>();
| env.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
| env.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jn.interfaces");
| env.put("java.naming.provider.url","jnp://localhost:1099");
| ctx = new InitialContext(env);
|
| NamingEnumeration list = ctx.list("");
|
| while (list.hasMore()) {
| NameClassPair nc = (NameClassPair) list.next();
|
| System.out.println(nc);
And the result of that is:
| TopicConnectionFactory: org.jboss.naming.LinkRefPair
| jmx: org.jnp.interfaces.NamingContext
| HTTPXAConnectionFactory: org.jboss.mq.SpyXAConnectionFactory
| ConnectionFactory: org.jboss.mq.SpyConnectionFactory
| UserTransactionSessionFactory: $Proxy12
| HTTPConnectionFactory: org.jboss.mq.SpyConnectionFactory
| XAConnectionFactory: org.jboss.mq.SpyXAConnectionFactory
| UserTransaction: org.jboss.tm.usertx.client.ClientUserTransaction
| UILXAConnectionFactory: javax.naming.LinkRef
| UIL2XAConnectionFactory: javax.naming.LinkRef
| queue: org.jnp.interfaces.NamingContext
| console: org.jnp.interfaces.NamingContext
| UIL2ConnectionFactory: javax.naming.LinkRef
| HiLoKeyGeneratorFactory: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory
| UILConnectionFactory: javax.naming.LinkRef
| EventDispatcher: org.jboss.ws.eventing.mgmt.DispatcherDelegate
| QueueConnectionFactory: org.jboss.naming.LinkRefPair
But ... I don't know exacty do what you are telling me. Could you tell me how I could do that?
Thanks a lot!
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4113218#4113218
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4113218
18 years, 4 months
[Persistence, JBoss/CMP, Hibernate, Database] - unable to update entity in collection
by u268
Another odd thing with hibernate:
using the code below I'm unable to update entity data but successfully may add new one to collection :
anonymous wrote : /**
| * Writes qualification info into DB
| *
| * @param qualification object model to be updated
| * @return true if successfull
| * @throws Exception
| */
| public boolean saveQualification(UsersAcademicQualifications qualification) throws Exception {
| if (qualification != null) {
|
| usersAcademicQualificationsHome.setInstance(qualification);
|
| if (qualification.getId() != null && qualification.getId().trim().length() > 0) {
| usersAcademicQualificationsHome.update();
| }
| else {
| usersAcademicQualificationsHome.persist();
| }
|
| usersAcademicQualificationsHome.getEntityManager().flush();
|
| //updating related entities
| usersAcademicQualificationsHome.setId(qualification.getId());
| qualification = usersAcademicQualificationsHome.find();
|
| //adding new qualification to related Users object
| {
| qualification.getUsers().getUsersAcademicQualifications().add(qualification);
| usersFacade.saveUser(qualification.getUsers());
| }
|
| return true;
| }
| return false;
| }
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4113216#4113216
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4113216
18 years, 4 months
[JBoss Seam] - unable to update entity in collection
by u268
Another odd thing with hibernate:
using the code below I'm unable to update entity data but successfully may add new one to collection :
/**
| * Writes qualification info into DB
| *
| * @param qualification object model to be updated
| * @return true if successfull
| * @throws Exception
| */
| public boolean saveQualification(UsersAcademicQualifications qualification) throws Exception {
| if (qualification != null) {
|
| usersAcademicQualificationsHome.setInstance(qualification);
|
| if (qualification.getId() != null && qualification.getId().trim().length() > 0) {
| usersAcademicQualificationsHome.update();
| }
| else {
| usersAcademicQualificationsHome.persist();
| }
|
| usersAcademicQualificationsHome.getEntityManager().flush();
|
| //updating related entities
| usersAcademicQualificationsHome.setId(qualification.getId());
| qualification = usersAcademicQualificationsHome.find();
|
| //adding new qualification to related Users object
| {
| qualification.getUsers().getUsersAcademicQualifications().add(qualification);
| usersFacade.saveUser(qualification.getUsers());
| }
|
| return true;
| }
| return false;
| }
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4113214#4113214
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4113214
18 years, 4 months
[JBoss Seam] - How to set and get cookie in seam?
by Stateless Bean
Hi,
I have one stateless bean in my app, and my scenario is:
1. first time visit page set cookie with some value,
2. second and more visits check if cookie exist and read it's value.
I don't know where is my problem, each time I read only 2 cookies whitch aren't mine:
1. session id cookie
2. identity cookie
| package pl.sguni.universum;
|
| import java.math.BigInteger;
| import java.util.Random;
|
| import org.jboss.seam.ScopeType;
|
| import javax.ejb.EJBException;
| import javax.ejb.Stateless;
| import javax.ejb.TransactionAttribute;
| import javax.ejb.TransactionAttributeType;
| import javax.faces.context.FacesContext;
| import javax.persistence.Query;
| import javax.servlet.http.Cookie;
| import javax.servlet.http.HttpServletRequest;
| import javax.servlet.http.HttpServletResponse;
|
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.Scope;
| import org.jboss.seam.annotations.web.RequestParameter;
|
| import pl.sguni.constants.LetterType;
| import pl.sguni.engine.BattleSystem;
| import pl.sguni.model.Moves;
|
| @Stateless
| @Scope(ScopeType.SESSION)
| @Name("advAction")
| public class AdvAction extends BattleSystem implements AdvConsole {
| public AdvAction() {}
|
| @In
| protected FacesContext facesContext;
|
| @RequestParameter
| private String id;
|
| @In("#{remoteAddr}") private String ipString;
| //*******************************************************************************
| @TransactionAttribute(TransactionAttributeType.REQUIRED)
| public String adv() {
| String ret = "/AdvDone.xhtml";
| try {
| long a = System.currentTimeMillis();
| //=================================================
| if ((id.length() > 0) && (ipString.length() > 0)) {
| if (!checkCookie()) {
| createCookie(ipString);
| ret = "/Adv.xhtml";
| }
| }
| //=================================================
| long b = System.currentTimeMillis();
| System.out.println("TIME: " + (b - a) + " ms.");
| } catch(EJBException e) {
| log.error("User: ->advAction - adv(): " + e.getMessage());
| }
| return ret;
| }
|
|
| private void createCookie(String value) {
| Cookie cookie = new Cookie("adv", id);
| cookie.setMaxAge(0);
| cookie.setSecure(false);
| cookie.setVersion(32140800);
| HttpServletResponse res = (HttpServletResponse)facesContext.getExternalContext().getResponse();
| res.addCookie(cookie);
| }
| public boolean checkCookie() {
| String cookieName = null;
| Cookie[] cookie = ((HttpServletRequest)facesContext.getExternalContext().getRequest()).getCookies();
|
| if(cookie != null && cookie.length > 0) {
| System.out.println("Cookie : [" + cookie + "] of length : " + cookie.length);
| for (int i = 0; i < cookie.length;i++) {
| Cookie currentCookie = cookie;
| cookieName = currentCookie.getName();
| if (cookieName.contentEquals("adv")) {
| System.out.println("DEBUG:cookie_value = " + currentCookie.getValue());
| return true;
| }
| }
| } else
| System.out.println("Cannot find any cookie");
| return false;
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4113213#4113213
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4113213
18 years, 4 months