Skip to main content

Ejb3 help needed( )

2 replies [Last post]
shruthifcg
Offline
Joined: 2007-05-01
Points: 0

hi

I have developed one enterprise application.In client refers the session bean in turn session bean refers the entity bean.
But the problem is when i run that application i am not getting desired output.I ahve used JNDI look up to refer the bean.
i am using netbeansIDE5.5 and sun's application server

i think my web.xml ( )is not correcct.
content of web.xml (partly)

TaskSessionLocal
Session

TaskEjb.TaskSessionLocal
TaskSession

can anybody please tell me what all these signifies( and all)

regards
shruthi

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
shekargowda
Offline
Joined: 2003-06-13
Points: 0

Send us more information, What about ejb-jar.xml ?

Sample EJB Structure.
HelloWorldLdap/
EjbLdapbean.class
EjbLdap.class
EjbLdapHome.class
EjbLdapClient.class
META-INF/
ejb-jar.xml

shruthifcg
Offline
Joined: 2007-05-01
Points: 0

hi
i am going to list out all the details.Plz help me,y i am not getting desired out put.

[u]Application.xml[/u]


TaskApp


TaskApp-war.war
/TaskApp-war



TaskApp-ejb.jar


***********************************************************************************************

[b]Persiste.xml[/b]

oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider sqltest
TaskEjb.Category

**********************************************************************************************
[b]sun.ejb.jar.xml[/b]





***********************************************************************************************
Category.java(EnityBean)

/*
* Category.java
*
* Created on May 2, 2007, 11:27 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package TaskEjb;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
* Entity class Category
*
* @author sbgangad
*/
@Entity
@Table(name = "Category")
@NamedQueries( {
@NamedQuery(name = "Category.findByCategoryId", query = "SELECT c FROM Category c WHERE c.categoryId = :categoryId"),
@NamedQuery(name = "Category.findByCategory", query = "SELECT c FROM Category c WHERE c.category = :category")
})
public class Category implements Serializable {

@Id
@Column(name = "CategoryId", nullable = false)
private String categoryId;

@Column(name = "Category", nullable = false)
private String category;

/** Creates a new instance of Category */
public Category() {
}

/**
* Creates a new instance of Category with the specified values.
* @param categoryId the categoryId of the Category
*/
public Category(String categoryId) {
this.categoryId = categoryId;
}

/**
* Creates a new instance of Category with the specified values.
* @param categoryId the categoryId of the Category
* @param category the category of the Category
*/
public Category(String categoryId, String category) {
this.categoryId = categoryId;
this.category = category;
}

/**
* Gets the categoryId of this Category.
* @return the categoryId
*/
public String getCategoryId() {
return this.categoryId;
}

/**
* Sets the categoryId of this Category to the specified value.
* @param categoryId the new categoryId
*/
public void setCategoryId(String categoryId) {
this.categoryId = categoryId;
}

/**
* Gets the category of this Category.
* @return the category
*/
public String getCategory() {
return this.category;
}

/**
* Sets the category of this Category to the specified value.
* @param category the new category
*/
public void setCategory(String category) {
this.category = category;
}

/**
* Returns a hash code value for the object. This implementation computes
* a hash code value based on the id fields in this object.
* @return a hash code value for this object.
*/
@Override
public int hashCode() {
int hash = 0;
hash += (this.categoryId != null ? this.categoryId.hashCode() : 0);
return hash;
}

/**
* Determines whether another object is equal to this Category. The result is
* true if and only if the argument is not null and is a Category object that
* has the same id field values as this object.
* @param object the reference object with which to compare
* @return true if this object is the same as the argument;
* false otherwise.
*/
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Category)) {
return false;
}
Category other = (Category)object;
if (this.categoryId != other.categoryId && (this.categoryId == null || !this.categoryId.equals(other.categoryId))) return false;
return true;
}

/**
* Returns a string representation of the object. This implementation constructs
* that representation based on the id fields.
* @return a string representation of the object.
*/
@Override
public String toString() {
return "TaskEjb.Category[categoryId=" + categoryId + "]";
}

}
***********************************************************************************************
[b]TaskSessionBean.java[/b]

/*
* TaskSessionBean.java
*
* Created on April 27, 2007, 12:27 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package TaskEjb;

import javax.ejb.Stateless;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
*
* @author sbgangad
*/
@Stateless
@TransactionManagement(value=TransactionManagementType.CONTAINER)

public class TaskSessionBean implements TaskEjb.TaskSessionRemote {
/** Creates a new instance of TaskSessionBean */
@PersistenceContext(unitName="TaskApp-ejbPU")
private EntityManager em;
public TaskSessionBean() {
}

public Category searchForCustomer(String id){

Category cat= (Category)em.find(Category.class, id);
return cat;
}
}
***********************************************************************************************[b]TaskSessionLocal.java[/b]

package TaskEjb;

import javax.ejb.Local;

/**
* This is the business interface for TaskSession enterprise bean.
*/
@Local
public interface TaskSessionLocal {
TaskEjb.Category searchForCustomer(String id);
}

***********************************************************************************************
[b]TaskSessionRemote.java[/b]

package TaskEjb;

import javax.ejb.Remote;

/**
* This is the business interface for TaskSession enterprise bean.
*/
@Remote
public interface TaskSessionRemote {
TaskEjb.Category searchForCustomer(String id);

}
*********************************************************************************************
customer.jsp( jsp page invokes the session bean)

<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ page import="TaskEjb.Category" %>
<%@ page import="TaskEjb.Category" %>
<%@ page import="TaskEjb.TaskSessionLocal" %>
<%@ page language="java" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Collection" %>
<%@ page import="javax.ejb.ObjectNotFoundException" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import='java.util.*' %>




JSP Page



<%
String text = request.getParameter("name");
if (text != null && !"".equals(text)) {
try {

InitialContext ic = new InitialContext();

Object o = ic.lookup("java:comp/env/TaskSessionLocal");
out.println("lookup");
TaskSessionLocal tskSession = (TaskSessionLocal) o;

List categoryList=new ArrayList(); //creating empty list handles any errors gracefully.

Category category = tskSession.searchForCustomer(text);%>

<%=category.getCategory()%>
<% }

catch(Exception e)
{
System.err.println("Error");
}

}
%>

Result



***********************************************************************************************
[b]sun-web.xml[/b]




/TaskApp-war

Enable debug info compilation in the generated servlet class
Maintain a one-to-one correspondence between static content and the generated servlet class' java code


**********************************************************************************************
[b]web.xml[/b]

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">


30




customer.jsp


TaskSessionLocal
Session

TaskEjb.TaskSessionLocal
TaskSession