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





View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3947637#3947637

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3947637


-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to