Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8264773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:34:30+00:00 2026-06-08T04:34:30+00:00

I seem to be having what I believe is a ClassLoader problem using db4o

  • 0

I seem to be having what I believe is a ClassLoader problem using db4o with NetBeans. When I run the exact same code from the terminal with the same jar files from …/jre/lib/ext, everything works fine. The issue is that when I make a native query on some Classes that are loaded at runtime using a ClassLoader, I get an empty List from the database where I should definitely be getting a List with some elements (as I said, the same code works fine from the command line). I feel like this may be because the NetBeans ClassLoader works differently than the JVM ClassLoader, but I don’t know, I’m certainly no expert on either. Here is the code from my main function…..

////////////////////////////////////////////////////////////////////////////////////////////
package gql;

import java.io.*;
import java.util.*;
import com.db4o.*;

public class GQL {
    ////////////////////////////////////////////////////////////////////////////
    // GLOBAL VARIABLES
    ////////////////////////////////////////////////////////////////////////////
    private static ObjectSet dbObjects;
    private static LinkedList classes = new LinkedList();
    private static String dbPath, classPath;
    private static ObjectContainer db;
    private static ClassLoader coreClassLoader =
            ClassLoader.getSystemClassLoader();
    private static ClassLoader subClassLoader =
            ClassLoader.getSystemClassLoader();

    public static void main(String[] args) {
        ////////////////////////////////////////////////////////////////////////
        // CREATE DATABASE OBJECT
        ////////////////////////////////////////////////////////////////////////
        // If no path to a database is provided on the command line, print
        // error and exit program
        if (args.length < 1) {
           System.err.println("\nError: no database path provided.\n");
           return;
        } else if (args.length > 1) {
           dbPath = args[0];
           // TODO - dubug command line classpath
           classPath = args[1];
           db = Db4o.openFile(dbPath);
        } else {     // We assume that the database Classes are stored somewhere
           dbPath = args[0];    // along the CLASSPATH, and therefore classPath
           classPath = "";      // can be left empty
           db = Db4o.openFile(dbPath);
        }

        System.out.print("GQL> ");

        // The prompt of the interpreter is within a do-while loop, which can
        // be terminated by entering "exit"
        do {
           try {

               /////////////////////////////////////////////////////////////////
               // READ IN QUERY FILE
               /////////////////////////////////////////////////////////////////
               // We create a Scanner object to read tokens from the standard in
               // stream - these will be our DLOG files provided by the user
               Scanner fileScanner = new Scanner(System.in);
               String GQLFile = fileScanner.next();

               // Break loop and exit program if user enters "exit"
               if (GQLFile.equalsIgnoreCase("exit")) {
                   break;

               // If the user input is not preceeded by "@" and teminated with
               // ";" then the input is invalid - the user is prompted again
               } else if (!(GQLFile.substring(0,1).equals("@")) ||
                           !(GQLFile.substring(GQLFile.length()-1,
                               GQLFile.length()).equals(";"))) {

                   System.out.println("\nInvalid input.\nUsage:     "
                           + " @filename;\n");
                   System.out.print("GQL> ");
                   continue;

               } else {

                   // Parse out the "@" and ";" from the user's input and send
                   // this to a file Reader object
                   GQLFile = GQLFile.substring(1,GQLFile.length()-1);
               }

               // Now we create a reader object and give it the user's parsed
               // input - in the event of a FileNotFoundException, the user is
               // prompted again
               Reader reader;
               try {
                   reader = new FileReader(GQLFile);
               } catch (FileNotFoundException e) {
                   System.out.println("\nFile " + GQLFile +
                           " does not exist.\n");
                   System.out.print("GQL> ");
                   continue;
               }

               /////////////////////////////////////////////////////////////////
               // PARSE QUERY
               /////////////////////////////////////////////////////////////////
               // The parser and Lexer objects are created in the parser.java
               // and Lexer.java files, respectively - The parser takes the
               // Lexer as an argument - the value variable generated by the
               // parse() method will return the topmost grammar construct,
               // which in this case is a Query object
               parser p = new parser(new Lexer(reader));                      

               Query query = (Query) p.parse().value;
               /////////////////////////////////////////////////////////////////
               System.out.println("\n----------------------------Input Query-----" +
                       "-----------------------\n");

               System.out.println("\n                        SUCCESSFUL PARSE   " +
                       "                       \n");

               System.out.println("--------------------------------------" +
                       "------------------------------\n");
               /////////////////////////////////////////////////////////////////

               /////////////////////////////////////////////////////////////////
               // LOAD ALL CLASSES USED IN DATABASE INTO RUNTIME
               /////////////////////////////////////////////////////////////////
               // databse Classes should be kept on the CLASSPATH, or the path
               // to these classes should be provided as a second command line
               // argument
               boolean coreClassesLoaded = loadCoreClasses(coreClassLoader,
                       classPath);
               if (!coreClassesLoaded) {
                   System.err.println("\nError: one or more of core Classes"
                           + "Node, Egge and SimplePath could not be found.\n");
                   db.close();
                   return;
               }
               //
               System.out.println("Core classes loaded.\n");
               boolean subclassesLoaded = query.loadSubclasses(subClassLoader,
                       classPath);
               if (!subclassesLoaded) {
                   System.err.println("\nError: subclasses could not be" +
                           " loaded.\n");
                   db.close();
                   return;
               }
               //
               System.out.println("Subclasses loaded.\n");


               /////////////////////////////////////////////////////////////////
               // MAKE SURE THE DATABASE ACTUALLY CONTAINS SOME OBJECTS AND,
               // IF SO, PUT AN INSTANCE OF EACH CLASS REPRESENTED INTO THE
               // LINKEDLIST CLASSLIST - SINCE WE LOADED THE DATABASE CLASSES
               // INTO THE RUNTIME ENVIRONMENT, OBJECTS RETURNED BY DATABASE
               // QUERIES WILL REMAIN TRUE TO THEIR TYPE; IF WE HADN'T DONE
               // THIS, THESE OBJECTS WOULD BE RETURNED AS TYPE GENERICOBJECT
               /////////////////////////////////////////////////////////////////
               dbObjects = db.queryByExample(Object.class);
               if (dbObjects.hasNext()) {
                  query.addClassesToList(dbObjects, classes);
               } else {
                   System.err.println("\nError: no objects in database.\n");
                   db.close();
                   return;
               }
               //
               System.out.println(classes);

               /////////////////////////////////////////////////////////////////
               // SEMANTIC CHECKS                                             //
               /////////////////////////////////////////////////////////////////
               boolean headArgsAreSet = query.setHeadArgClasses(classes);    
               if (!headArgsAreSet) {                                        
                   db.close();
                   return;                                                   
               }                                                             
               boolean typesMatch = query.checkQueryTypes(db);         
               if (!typesMatch) {                                            
                   db.close();
                   return;
               }              

               /////////////////////////////////////////////////////////////////
               // EVALUATION
               /////////////////////////////////////////////////////////////////
               query.evaluateQuery(db);

           } catch (Exception e) {
               System.out.println("\nSYNTAX ERROR\n");
               e.printStackTrace();
           }

           System.out.print("GQL> ");
        } while (true);

        System.out.println("\nExiting...\n");
        db.close();
    }

    private static boolean loadCoreClasses(ClassLoader coreClassLoader,
            String classPath) {
        try {
            coreClassLoader.loadClass("Node");
            coreClassLoader.loadClass("Edge");
            coreClassLoader.loadClass("SimplePath");
        } catch (ClassNotFoundException cnfe) {
            return false;
        }
        return true;
    }
}



////////////////////////////////////////////////////////////////////////////////////////////

The strange thing is, the classes I need are definitely getting loaded into the runtime environment, as I use them to set some Class member variables, for example in the “SEMANTIC CHECKS” section. So it’s like the application can see the dynamically loaded Classes, but the db4o API/database cannot. Also, I have the Class jar and the db4o jar set up as Netbeans libraries, not just in …/jre/lib/ext. Here’s a snippet of the code in the Class where I actually use the db4o native query that’s giving me problems…

////////////////////////////////////////////////////////////////////////////////////////////

   public void evaluateQuery(ObjectContainer db) {
        if (this.hasPredicate) {
            ;
        } else {
            if (this.isNode) {
                List nodes = db.query(new Predicate() {
                    @Override
                    public boolean match(Node node) {
                        return (node.getName().equals("5"));
                    }
                });
                System.out.println("\n_________________RESULT__________________________");
                System.out.println("\nNode: " + nodes.get(0).getName()
                        //+ ".\n");
            }
        }
    }

////////////////////////////////////////////////////////////////////////////////////////////

… if I do the following instead I still get an empty List…

////////////////////////////////////////////////////////////////////////////////////////////


   public void evaluateQuery(ObjectContainer db) {
        if (this.hasPredicate) {
            ;
        } else {
            if (this.isNode) {
                List nodes = db.queryByExample(Node.class);
                System.out.println(nodes.size());
                for (int i = 0; i < nodes.size(); i++) {
                    System.out.println("\nNode: " + nodes.get(i).getName());
                }
            }
        }
    }

////////////////////////////////////////////////////////////////////////////////////////////
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T04:34:33+00:00Added an answer on June 8, 2026 at 4:34 am

    Well it seems like this is a bug in Linux/Netbeans for Linux/Db4o. I used the exact same source files on a windows box and everything worked fine. I’m pretty disappointed, I don’t want to have to use windows for this project. :/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I seem to be having a problem removing the image in UIScrollView. I was
I seem to be having a problem checking if a string exists in my
I seem to be having trouble with my code. I need to say: if
I seem to be having a problem with checking for list equality. In my
I seem to be having a problem with my footer growing to 100% width
Hi all I seem to be having a problem with my jQuery mobile script.
Okay, I seem to be having a problem. I'm trying to create a twicker
I'm having a problem with jQuery/Ajax/JSON. I'm using a jQuery ajax post like so...
I'm having trouble within a block of code that I believe is related to
I'm having a problem creating webservices through nuSOAP (although i believe my problem has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.