[EJB 3.0] - EJB 3.0 and env-entry injection
by Ondrej Zizka
Ondrej Zizka [http://community.jboss.org/people/ozizka%40redhat.com] created the document:
"EJB 3.0 and env-entry injection"
To view the document, visit: http://community.jboss.org/docs/DOC-15944
--------------------------------------------------------------
package org.acme;
public class MyClass {
@Resource(name="providerURL") String field;
}
<env-entry>
<env-entry-name>providerURL</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>ldap://localhost:389/</env-entry-value>
</env-entry>
OR
package org.acme;
public class MyClass {
@Resource String field;
}
<env-entry>
<env-entry-name>org.acme.MyClass/field</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>ldap://localhost:389/</env-entry-value>
</env-entry>
OR
package org.acme;
public class MyClass {
String field;
}
<env-entry>
<env-entry-name>providerUrl</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>ldap://localhost:389/</env-entry-value>
<injection-target>
<injection-target-class>org.acme.MyClass</injection-target>
<injection-target-name>field</injection-target-name>
</injection-target>
</env-entry>
@Resource int maxExemptions = 4;
<env-entry>
<env-entry-name>maxExemptions</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>15</env-entry-value>
</env-entry>
If you download the entire source from CVS (jboss-head), there are examples in the ejb3 JUnit tests. Take a look at the enventry test. Here is an example bean and ejb-jar.xml
@Stateless(name="TestEnvEntry")
@Remote(TestEnvEntry.class)
@RemoteBinding(jndiBinding="TestEnvEntry")
public class TestEnvEntryBean implements TestEnvEntry
{
private static final Logger log = Logger.getLogger(TestEnvEntryBean.class);
@Resource(name="maxExceptions") private int maxExceptions = 4;
@Resource private int numExceptions = 3;
private int minExceptions = 1;
public int getMaxExceptions() { return maxExceptions; }
public int getNumExceptions() { return numExceptions; }
public int getMinExceptions() { return minExceptions; }
}
<ejb-jar>
<display-name>EnvEntry Tests</display-name>
<enterprise-beans>
<ejb-name>TestEnvEntry</ejb-name>
<env-entry>
<env-entry-name>maxExceptions</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>15</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>minExceptions</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>5</env-entry-value>
<injection-target>
<injection-target-class>org.jboss.ejb3.test.enventry.TestEnvEntryBean</injection-target-class>
<injection-target-name>minExceptions</injection-target-name>
</injection-target>
</env-entry>
<env-entry>
<env-entry-name>org.jboss.ejb3.test.enventry.TestEnvEntryBean/numExceptions</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>10</env-entry-value>
</env-entry>
<ejb-name>ExtendedTestEnvEntry</ejb-name>
<env-entry>
<env-entry-name>maxExceptions</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>14</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>minExceptions</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>6</env-entry-value>
<injection-target>
<injection-target-class>org.jboss.ejb3.test.enventry.ExtendedTestEnvEntryBean</injection-target-class>
<injection-target-name>minExceptions</injection-target-name>
</injection-target>
</env-entry>
<env-entry>
<env-entry-name>org.jboss.ejb3.test.enventry.ExtendedTestEnvEntryBean/numExceptions</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>11</env-entry-value>
</env-entry>
</enterprise-beans>
</ejb-jar>
--------------
Here is an example.
All three work but I have shown the first 2 in this example
*ejb-jar.xml*
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="3.0"
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 ../../../testapp/ejb-jar_3_0.xsd ">
<enterprise-beans>
<session>
<ejb-name>com.suresh.ejb.test.HelloBean</ejb-name>
<remote>com.suresh.ejb.test.Hello</remote>
<ejb-class>com.suresh.ejb.test.HelloBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<env-entry>
<env-entry-name>com.suresh.ejb.test.HelloBean/urls</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>@ldap.url@</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>username</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>@user.name@</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>password</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>what</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>com.suresh.ejb.test.HelloBean/location</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>Australia</env-entry-value>
</env-entry>
<resource-ref>
<res-ref-name>jdbc/user</res-ref-name>
<res-type>javax.sql.Datasource</res-type>
<res-auth>Container</res-auth>
<mapped-name>java:UserDB</mapped-name>
</resource-ref>
</session>
</enterprise-beans>
</ejb-jar>
package com.suresh.ejb.test;
import java.sql.Connection;
import java.sql.ResultSet;
import javax.annotation.Resource;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import com.suresh.ejb.test.Hello;
@javax.ejb.Stateless(name="com.suresh.ejb.test.HelloBean")
@javax.ejb.TransactionAttribute (value=javax.ejb.TransactionAttributeType.SUPPORTS)
@javax.annotation.Resource(name="jdbc/user",
type=DataSource.class,
authenticationType=javax.annotation.Resource.AuthenticationType.CONTAINER,
mappedName="java:UserDB")
public class HelloBean implements Hello {
@Resource private String urls;
@Resource(name="username") private String provider;
@Resource(name="password") private String pwd;
@Resource private String location;
public String greet() {
return urls + " " + location + " " + pwd + " " + provider + " at " + greet1();
}
//example of datasource
public String greet1() {
String data = null;
Connection c = null;
try {
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:comp.ejb3/env/jdbc/user");
ResultSet rs = ds.getConnection().createStatement().executeQuery("select sysdate from dual");
while (rs.next()) {
data = rs.getString(1);
}
} catch (Exception e) {
System.err.println(e);
e.printStackTrace();
} finally {
try {
c.close();
} catch (Exception e) {
}
}
return data;
}
}
Hello.java
package comsuresh.ejb.test;
import javax.ejb.Remote;
@Remote
public interface Hello {
public String greet();
}
This article was generated from the following discussion: http://community.jboss.org/thread/106082 EJB 3.0 and env-entry injection
--------------------------------------------------------------
Comment by going to Community
[http://community.jboss.org/docs/DOC-15944]
Create a new document in EJB 3.0 at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=102&co...]
13 years, 11 months
[EJB 3.0] - How can I bind a JMS topic to an EJBs ENC?
by johk johk
johk johk [http://community.jboss.org/people/johk] created the discussion
"How can I bind a JMS topic to an EJBs ENC?"
To view the discussion, visit: http://community.jboss.org/message/565537#565537
--------------------------------------------------------------
I have an EJB defined as follows:
@Stateless(name="Search")
@TransactionAttribute(REQUIRED)
@Local(SearchEngine.class)
public class SearchEngineEJB
extends
AbstractEJB
implements
SearchEngine {
@Resource(
name="topic_conn_factory",
authenticationType=AuthenticationType.CONTAINER,
type=TopicConnectionFactory.class)
private TopicConnectionFactory _connectionFactory;
@Resource(
name="topic_broadcast",
authenticationType=AuthenticationType.CONTAINER,
type=Topic.class)
private Topic _broadcast;
...
}
I'm trying to register the appropriate objects from JNDI to the names specitied in the @Resource annotations. My jboss.xml is as follows:
<jboss>
<enterprise-beans>
<session>
<ejb-name>Search</ejb-name>
<resource-env-ref>
<resource-env-ref-name>topic_conn_factory</resource-env-ref-name>
<jndi-name>java:/JmsXA</jndi-name>
</resource-env-ref>
<resource-env-ref>
<resource-env-ref-name>topic_broadcast</resource-env-ref-name>
<jndi-name>topic/foo</jndi-name>
</resource-env-ref>
</session>
</enterprise-beans>
</jboss>
The binding for the connection factory works fine. However, when I deploy jBoss reports the following problem:
Deployment "vfszip:/home/.../cc7.ear/" is in error due to the following reason(s):
java.lang.RuntimeException: mapped-name or message-destination-link is required for topic_broadcast of deployment Search
*Could someone shed some light on hiw I can resolve this?*
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/565537#565537]
Start a new discussion in EJB 3.0 at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
13 years, 11 months
[EJB 3.0] - ManyToMany bidirectional - inverse side does not load the complete collection
by Nicole Schweighardt
Nicole Schweighardt [http://community.jboss.org/people/NSchweig] created the discussion
"ManyToMany bidirectional - inverse side does not load the complete collection"
To view the discussion, visit: http://community.jboss.org/message/564238#564238
--------------------------------------------------------------
Hi
I read a lot about eager and lazy fetching and so on but for this case I could not find a solution.
I have a relationship between 'appointment' and 'offer'. An appointment has a list with offers, an offer has a list with appointments. Offer is the owner side.
@Entity
public class Offer implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
...
//bidirectional
//Appointments that are in the offer
@ManyToMany(fetch=FetchType.EAGER)
@IndexColumn(name="INDEX_COL")
private List<Appointment> appointments = new ArrayList<Appointment>();
...}
@Entity
public class Appointment implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String title;
private String description;
//unidirektional
@ManyToOne
@JoinColumn(name="instructor")
private CmtUser instructor;
...
//bidirektional
@ManyToMany(fetch=FetchType.EAGER,mappedBy="appointments")
@IndexColumn(name="INDEX_COL")
private List<Offer> offers= new ArrayList<Offer>();
...}
If I load an offer from my database in my sessionbean 'OfferHandler', the list with the appointments is fully loaded. (see picture 1) (I tested it with the debugger to look into the collections in the sessionbean, too, not only with my web layer)
public List<Offer> getOffersForInstructor(Long instructorId) {
try{
Query q = em.createQuery("SELECT a from Offer a " +
"WHERE a.instructor.id = :instructorId ");
q.setParameter("instructorId",instructorId);
List<Offer> offers = (List<Offer>) q.getResultList();
return offers ;
}
catch(EntityNotFoundException ex){}
return null;
}
But on the other side if I try to load some appointments from my database the collection with the offers only contains the last saved offer! (see picture 2)
public List<Appointment> getFreeAppointments(Long instructorId) {
try{
Query q = em.createQuery("SELECT a from Appointment a " +
"WHERE a.instructor.id = :instructorId AND " +
"a.accepted =:false ");
q.setParameter("instructorId",instructorId);
q.setParameter("false",false);
List<Appointment> appointments = (List<Appointment>) q.getResultList();
return appointments;
}
In the database there is an jointable with the right entries:
f. example: (the first offer contains the first appointment, the second offer contains both appointments)
offers_id appointments_id INDEX_COL
1 1 0
2 1 0
2 2 1
I hope someone can help. I tested a lot to force loading the collection. f.example refreshing the appointments or loading the offers in the appointments with appointment.offers.size().
Thank you a lot
Nicki
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/564238#564238]
Start a new discussion in EJB 3.0 at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
13 years, 11 months
[jBPM] - jBPM 3.2 Enterprise - Unhandled exception in async node?
by Rohit Raghuwanshi
Rohit Raghuwanshi [http://community.jboss.org/people/rohit_r] created the discussion
"jBPM 3.2 Enterprise - Unhandled exception in async node?"
To view the discussion, visit: http://community.jboss.org/message/564967#564967
--------------------------------------------------------------
Hello all,
We have a jBPM 3.2.7 Enterprise deployed on Websphere 7.0 / Oracle 10g
The process scenario is as follows
*START -> success-node (async) -> exception-node (async) -> END*
Each node just logs an message to console. When we start a new instance of the process
1. *success-node* logs the message.
2. *exception-node* throws an uncaught exception.
After this we find that if we check the process instance status, it shows up in "*Running*" state with current node as *exception-node*. Is this the correct behavior? We were expecting the process to get rolled back to end of *success-node*.
Also from this exception state if we signal the process further it goes to *END* state. We were expecting the *exception-node* to get processed again as the transaction should have rolled back to the end of *success-node*.
The process archive is attached. Would really appreciate some help here as the process does not match our understanding of exception scenario in jBPM.
Thanks!
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/564967#564967]
Start a new discussion in jBPM at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
13 years, 11 months
[Beginner's Corner] - Problem locating war file for BRMS/Guvnor install
by Todd Springman
frozenrun [http://community.jboss.org/people/frozenrun] created the discussion
"Problem locating war file for BRMS/Guvnor install"
To view the discussion, visit: http://community.jboss.org/message/564566#564566
--------------------------------------------------------------
Hello,
Following the below steps there should be atleast one file with name drools-jbrms.war or guvnor.way. From reading web references the file should be drools-guvnor-5.1.0.war. I was not able to locate any such file from the zip file. Where is the needed .war file to install the BRMS/Guvnor?
>From the download page (link is below), I downloaded the Drools Guvnor, 5.1 Version (Guvnor, web based BRMS (WAR)) 57MB file.
h3. Installing the BRMS/Guvnor
Open http://www.jboss.org/drools/downloads.html http://www.jboss.org/drools/downloads.html in your web browser and look for the 'Drools BRMS' download section). This may have been renamed to Guvnor/version 5 by the time that you read this. In general, take the latest available version.
Download this file to a place that you will remember. Once the download has completed, extract (unzip) these files to a temporary folder it should contain at least one file, with the name drools-jbrms.war or guvnor.war.
Copy this .war file to the JBoss deploy directory. If you followed the same directory name as I did when installing JBoss, this should be C:\software\jboss\jboss-5.0.0.Beta4\server\default\deploy (that is, [wherever-you-installed-jboss]\server\default\deploy).
Make sure that JBoss is running. (If it isn't, start it as per the previous step by clicking on run.bat.)
Any help would be greatly appreicrated.
Thank you.
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/564566#564566]
Start a new discussion in Beginner's Corner at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
13 years, 11 months