Skip to Content
Former Member
May 16, 2007 at 11:06 PM

DAO pattern & Lookup datasource with NamingException in the same J2EE APP


Hello Experts:

I'm developing an J2EE application with EJB's for transactional operations (that works fine!) and I'm implementing the J2EE DAO Pattern using a DAO ConnectionFactory with OpenSQL/JDBC standard for Querying the DB, but here my problems begins:

The DAOConnectionFactory Singleton Class is placed in a java package inside the same application that holds my Entitys & Sessions (remember this ejb's works fine!) and I'm trying to get the "localy-configured-in-the-j2ee-application" alias-datasource for my DAO Querys, but "lookup" doesn't find this resource!!!.

I'm thinking, there's not remote access to this resouce because the DAO-CF is in the same context and JVM, but this appreciation is correct? or what I miss?

Another remark: I've been used the Telnet Administrator and the same lookup string is founded correctly!.

Here is the Codec:

public class ConexionFactory implements Serializable {
	private static ConexionFactory singleton = null;

	private DataSource ds;

	protected ConexionFactory() {
		String source = "jdbc/BURO_COMM";
		try {

			Context ctx = new InitialContext();
			ds = (DataSource) ctx.lookup(source);
			if (null == ds) {
				throw new RuntimeException("Couldn't get the datasource");
		} catch (NameNotFoundException e) {
			throw new RuntimeException(e.getMessage());
		} catch (NamingException e) {
			throw new RuntimeException(e.getMessage());


	public static ConexionFactory getInstance() {

		if (null == singleton) {
			singleton = new ConexionFactory();

		return singleton;
.... (some other methods)