Skip to main content

hibernate not bound

1 reply [Last post]
lema
Offline
Joined: 2007-07-23
Points: 0

hallo everybody.

i'm working with some examples of jboss, "jbossatwork" http://www.jbossatwork.com/downloads.html. but i'm stuck in 5th example.
as i get, the problem is in binding hibernate. when i try to run it through hibernate, a message like "hibernte not bound" appears on jboss4.

---------------this is a part from ControllerServlet.java:

if(VIEW_CAR_LIST_ACTION.equals(actionName))
{
CarDAO carDAO = new HibernateCarDAO();
request.setAttribute("carList", carDAO.findAll());

destinationPage = "/carList.jsp";

---------------this is HibernateCarDAO.java

package com.jbossatwork.dao;

import java.util.*;
import org.hibernate.*;
import com.jbossatwork.dto.CarDTO;
import com.jbossatwork.util.*;

public class HibernateCarDAO implements CarDAO
{
private List carList;
private static final String HIBERNATE_SESSION_FACTORY="java:comp/env/hibernate/SessionFactory";

public HibernateCarDAO()
{}

public List findAll()
{
List carList = new ArrayList();
Session session = null;

try
{
session = ServiceLocator.getHibernateSession(HIBERNATE_SESSION_FACTORY);
Criteria criteria = session.createCriteria(CarDTO.class);
carList = criteria.list();
}
catch (Exception e)
{
System.out.println(e);
}
finally
{
try
{
if (session != null) {session.close();}
}
catch (Exception e)
{
System.out.println(e);
}
}

return carList;
}

}
---------------this is JDBCCarDAO.java:

package com.jbossatwork.dao;

import java.util.*;
import java.sql.*;
import javax.sql.*;
import com.jbossatwork.dto.CarDTO;
import com.jbossatwork.util.*;

public class JDBCCarDAO implements CarDAO
{
private List carList;
private static final String DATA_SOURCE="java:comp/env/jdbc/JBossAtWorkDS";

public JDBCCarDAO()
{}

public List findAll()
{
List carList = new ArrayList();
DataSource dataSource = null;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;

try
{
dataSource = ServiceLocator.getDataSource(DATA_SOURCE);
conn = dataSource.getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from CAR");

while(rs.next())
{
CarDTO car = new CarDTO();
car.setId(rs.getInt("ID"));
car.setMake(rs.getString("MAKE"));
car.setModel(rs.getString("MODEL"));
car.setModelYear(rs.getString("MODEL_YEAR"));
carList.add(car);
}

}
catch (Exception e)
{
System.out.println(e);
}
finally
{
try
{
if(rs != null){rs.close();}
if(stmt != null){stmt.close();}
if(conn != null){conn.close();}
}
catch(Exception e)
{
System.out.println(e);
}
}

return carList;
}

}

-----------------------------------------------------------------------------------------------------
it works well when i change the part from ControllerServlet.java into:

if(VIEW_CAR_LIST_ACTION.equals(actionName))
{
CarDAO carDAO = new JDBCCarDAO();
request.setAttribute("carList", carDAO.findAll());

destinationPage = "/carList.jsp";

otherwise jboss gives an error message like:

INFO [STDOUT] com.jbossatwork.util.ServiceLocatorException: com.jbossatwork.util.ServiceLocatorException: javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: hibernate not bound]

pls, could anybody help me to find the problem?

lema

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
lema
Offline
Joined: 2007-07-23
Points: 0

hi there. i got an email from someone asking about this my question. but i couldn't find him on this forum. anyway, the problem was in using different hibernate and jboss versions.
in the tutorial book it starts explaining ch5 practice like this:
Hibernate is unique because it can run either in a J2EE container such as JBoss, or as a standalone service. [b]JBoss 4.0.2 ships standard with Hibernate 3.0.2.[/b]