-
1. Re: JBoss IDE and CMP
ebenezersamuel May 29, 2006 3:51 AM (in response to kmalinow)I am very new to EJBs. I have created a stateless session bean following the Fibo bean example. Now, I would like to create a Entity bean; does anyone know any tutorial like the Fibo bean? Any help would be greatly appreciated.
Regards,
Ebe. -
2. Re: JBoss IDE and CMP
jklanka May 30, 2006 9:28 AM (in response to kmalinow)Hi Guys Let me give some guide from my basic knowledge
1. CREATE TABLE 'Author' (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
)
2. Create a J2EE 1.4 project (BookStore) and add src folder and output folder bin (Like in the JBOSS-IDE tutorial)
3. Right Click on the Project >Property > XDoclets Configuration and Enable XDoclet. Now Right Click anywhere in the window and Click Add Standard > Standard EJB (Give any name. say EJB). Also Right Click again and select Add Standadard > Standard Web (for exampe give name Web)
Under EJB XDoclets keep only the following and remove other
deploymebntdescriptor
entitypk
filesset (set dir=src, and includes=**/*.java)
homeinterface
jboss (version=3.2 or 3)
remoteinterface
Under Web XDoclets keep only the following and remove the other
deploymebntdescriptor
filesset (set dir=src, and includes=**/*.java)
jbosswebxml (version=3.2 or 3)
4. Now Right Click on the projects New > Other > EJB Components >Entity Bean (Give name=Author,package=com.account,and select CMP 2.x and Remote options leave the other defualt)
5. Replace the following in the EntityBean
/**
* @ejb.bean name="Author"
* display-name="Name for Author"
* description="Description for Author"
* jndi-name="ejb/Author"
* type="CMP"
* cmp-version="2.x"
* view-type="remote"
* schema = "AuthorSchema"
* @jboss.unknown-pk
* class="com.account.AuthorPK"
* auto-increment="true"
*
* @jboss.entity-command
* name="mysql-get-generated-keys"
* class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCMySQLCreateCommand"
* @ejb.persistence table-name = "Author"
*/
Note : I used mySQL Database
May be you have to replace these line for Hypersonic
* @jboss.entity-command
* name="hsqldb-fetch-key"
* class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCHsqldbCreateCommand"
6. Now add the Virtual methods to the Entity Bean as follow
/**
* Getter for CMP Field id
*
* @ejb.pk-field
* @ejb.persistent-field
* @ejb.interface-method view-type="remote"
*/
public abstract Integer getId();
/**
* Setter for CMP Field id
*
* @ejb.interface-method view-type="remote"
*/
public abstract void setId(Integer value);
/**
* Getter for CMP Field name
*
*
* @ejb.persistent-field
* @ejb.interface-method view-type="remote"
*/
public abstract String getName();
/**
* Setter for CMP Field name
*
* @ejb.interface-method view-type="remote"
*/
public abstract void setName(String value);
(Note you can add these methods simple right Clicking the bean class > J2EE >Add CMP Field )
7. Now you can run the XDoclets to see the result
8. OK lets Add a Servlet Class and modify theXDoclets, init and doGet As Follow
**
* Servlet Class
*
* @web.servlet name="Test"
* display-name="Name for Test"
* description="Description for Test"
* @web.servlet-mapping url-pattern="/Test"
* @web.servlet-init-param name="A parameter"
* value="A value"
* @web.ejb-ref
* name="ejb/Author"
* type="Entity"
* home="com.account.AuthorHome"
* remote="com.account.Author"
* description="Reference to the Fibo EJB"
*
* @jboss.ejb-ref-jndi
* ref-name="ejb/Author"
* jndi-name="ejb/Author"
*/
...
public class Test ......
private AuthorHome home;
public void init(ServletConfig config) throws ServletException {
try {
Context context = new InitialContext();
Object ref = context.lookup("java:comp/env/ejb/Author");
home = (AuthorHome) PortableRemoteObject.narrow(ref, AuthorHome.class);
} catch (Exception e) {
throw new ServletException("Lookup of java:/comp/env/ failed" + e);
}
}
-----
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException,
IOException {
resp.setContentType("text/html");
PrintWriter out=resp.getWriter();
try {
int myid=1;
Integer parsed_myid=new Integer(myid);
AuthorPK pk=new AuthorPK(parsed_myid);
Author bean = home.findByPrimaryKey(pk);
out.print(bean.getName());
} catch (Exception e) {
out.print(e);
}
}
And now Run XDoclets
10. Now Lets Add the application.xml file (JBOSS-IDE tutorails gives the steps for those)
Right Click projects>New>Other>JBoss-IDE > Descriptors>EAR 1.4 Deployment Descriptor
11. Now Lets Package the projects (Again JBOSS-IDE tutorails gives the steps for those)
Right Click the project>property>Packaging Configuration
Ok the package should looks like below
author-ejb.jar
/MyEntityProject/bin
/MyEntityProject/src/META-INF/ejb-jar.xml -> META-INF
/MyEntityProject/src/META-INF/jboss.xml -> META-INF
/MyEntityProject/src/META-INF/jbosscmp-jdbc.xml -> META-INF
author-web.war
/MyEntityProject/bin
/MyEntityProject/src/WEB-INF/jboss-web.xml -> WEB-INF
/MyEntityProject/src/WEB-INF/webb.xml -> WEB-INF
author.ear
/MyEntityProject/author-ejb.jar
/MyEntityProject/author-web.war
/MyEntityProject/META-INF/application.xml -> META-INF12.
Now Run the packaging ok we done it
Note : I am also little new so please excuse me if any thing if I tild wrong. I tried little hard to find this autoincrement integer field primary key concept to use in JBOSS. But really thanks to the forums -
3. Re: JBoss IDE and CMP
dlehdcjs May 31, 2006 12:20 AM (in response to kmalinow)Thanks
I'd try this right now.
This is what I really wanted to know. ^^