that doesn't work either. Im actually new to EJBs Im using netbeans and hope I have done this stuff right. Here is the thing Im tryin to do USe hibernate for persistence. Use a stateless eJB to just run a from <tablename> to fetch all rowa. Use a servlet to invoke the EJB remote class and finally use a
JSP to invoke the servlet. Here are My classes..
EJBTest.java
______________
package hobernatetest;
import javax.ejb.Stateless;
import org.hibernate.Session;
import org.hibernate.Query;
import java.util.List;
import javax.persistence.PersistenceContext;
@Stateless
public class EJBTest implements EJBTestRemote, EJBTestLocal {
@PersistenceContext(unitName = "hibernate.cfg.xml")
Session session = null;
public EJBTest(){
this.session = NewHibernateUtil.getSessionFactory().getCurrentSession();
org.hibernate.Transaction tx = session.beginTransaction();
}
public List businessMethod() {
List<Tbhhcfacility> facility = null;
try {
Query q = session.createQuery ("from Tbhhcfacility as facility ");
facility = (List<Tbhhcfacility>) q.list();
} catch (Exception e) {
e.printStackTrace();
}
return facility;
}
// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method")
}
EJBTestRemote.java
_________________
package hobernatetest;
import java.util.List;
import javax.ejb.Remote;
@Remote
public interface EJBTestRemote {
List businessMethod();
}
TestServlet.java
______________
package hobernatetest;
import java.io.*;
import javax.ejb.EJB;
import javax.servlet.*;
import javax.servlet.http.*;
public class TestServlet extends HttpServlet {
@EJB
private EJBTestRemote testEJB;
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet TestServlet</title>");
out.println("</head>");
out.println("<body>");
out.println(testEJB.businessMethod());
out.println("</body>");
out.println("</html>");
}
}
hibernate.cfg.xml
_________________
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/in</property>
<property name="hibernate.connection.username">root</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<mapping resource="hobernatetest/Tbhhcfacility.hbm.xml"/>
<mapping resource="hobernatetest/Tbscfacility.hbm.xml"/>
<mapping resource="hobernatetest/PhpSession.hbm.xml"/>
<mapping resource="hobernatetest/Tbdcsfacility.hbm.xml"/>
<mapping resource="hobernatetest/Tbsbafacility.hbm.xml"/>
<mapping resource="hobernatetest/Tbsphefacility.hbm.xml"/>
<mapping resource="hobernatetest/Tbncpafacility.hbm.xml"/>
</session-factory>
</hibernate-configuration>
The persistent classes I created and reveng.xml seem to work fine because I can run the HQL query in the IDE and it returns all the rows for the table.
Thanks for the help guys and any tutorials to just achive the same functionality would help im not real specific on just makin this work