-
1. Re: StackOverflowError Looking Up Stateless EJB3 Bean
michael.litherland May 22, 2006 12:57 PM (in response to michael.litherland)I may have an idea why it's failing. I'm deploying the EJBs in a .jar and the web app separately as a .war. Is there something in this setup that could cause a failure like this? Previously I had tried to combine the two into a single .ear, but had other issues so I broke them out to make things more clear for me.
Thanks,
Mike -
2. Re: StackOverflowError Looking Up Stateless EJB3 Bean
bdecoste May 22, 2006 2:31 PM (in response to michael.litherland)You should be able to deploy as separate jar/war and in a single ear.
Can you post the deployment descriptions and annotated bean classes? Looks like you may have a cyclical jndi link that is causing the overflow. -
3. Re: StackOverflowError Looking Up Stateless EJB3 Bean
michael.litherland May 23, 2006 12:31 PM (in response to michael.litherland)OK, here are my ejbs, two stateless and en entity:
package calctest.ejb; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; /** * * @author mike */ @Stateless public class CalculatorBean implements CalculatorRemote, CalculatorLocal { @PersistenceContext private EntityManager em; /** Creates a new instance of CalculatorBean */ public CalculatorBean() { } public float add(float a, float b) { float result = a + b; Calculations c = new Calculations(a, b, "add", result); em.persist(c); return result; } public float subtract(float a, float b) { float result = a - b; Calculations c = new Calculations(a, b, "subtract", result); em.persist(c); return result; } }
package calctest.ejb; import java.util.List; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; /** * * @author mike */ @Stateless public class HistoryBean implements HistoryRemote, HistoryLocal { @PersistenceContext private EntityManager em; /** Creates a new instance of HistoryBean */ public HistoryBean() { } public List getHistory() { return em.createQuery("from Calculations c").getResultList(); } }
package calctest.ejb; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; /** * * @author mike */ @Entity @Table(name = "calculations") public class Calculations implements Serializable { @Id @Column(name = "id", nullable = false) private Integer id; @Column(name = "floatOne") private Float floatOne; @Column(name = "floatTwo") private Float floatTwo; @Column(name = "operation") private String operation; @Column(name = "result") private Float result; /** Creates a new instance of Calculations */ public Calculations() { } public Calculations(float floatOne, float floatTwo, String operation, float result) { this.floatOne = floatOne; this.floatTwo = floatTwo; this.operation = operation; this.result = result; } public Calculations(Integer id) { this.id = id; } public Integer getId() { return this.id; } public void setId(Integer id) { this.id = id; } public Float getFloatOne() { return this.floatOne; } public void setFloatOne(Float floatOne) { this.floatOne = floatOne; } public Float getFloatTwo() { return this.floatTwo; } public void setFloatTwo(Float floatTwo) { this.floatTwo = floatTwo; } public String getOperation() { return this.operation; } public void setOperation(String operation) { this.operation = operation; } public Float getResult() { return this.result; } public void setResult(Float result) { this.result = result; } public int hashCode() { int hash = 0; hash += (this.id != null ? this.id.hashCode() : 0); return hash; } public boolean equals(Object object) { if (object == null || !this.getClass().equals(object.getClass())) { return false; } Calculations other = (Calculations)object; if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) return false; return true; } public String toString() { //TODO change toString() implementation to return a better display name return "" + this.id; } }
I was playing with trying to use @EJB to inject the stateless beans instead of using the direct lookup code (this doesn't work apparently unless you are in a single ear?) so I have things kind of messed up in my deployment descriptor right now. But this is what it looked like before:<ejb-ref> <ejb-ref-name>ejb/CalculatorBean</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <home>calctest.ejb.CalculatorLocal</home> <remote>calctest.ejb.CalculatorRemote</remote> </ejb-ref> <ejb-ref> <ejb-ref-name>ejb/HistoryBean</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <home>calctest.ejb.HistoryLocal</home> <remote>calctest.ejb.HistoryRemote</remote> </ejb-ref>
Thanks for the help,
Mike -
4. Re: StackOverflowError Looking Up Stateless EJB3 Bean
bdecoste May 25, 2006 8:30 PM (in response to michael.litherland)You can use @EJB injection without an ear, but you need to specify the global jndi binding of the target bean with the mappedName param.
Do you have a corresponding jboss.xml where the <jndi-name>'s are specified for the <ejb-ref>?