0

I am setting up hyperjaxb to run in eclipse using this tutorial. So far, I have gotten it to marshal and unmarshal, but it does not yet trigger hbm2ddl to create the tables in the database, and it is not clear where in the eclipse directory structure I should locate the Main.java and TestFunctions.java classes that I created to run the code from the tutorial link above. How can I alter my eclipse configuration to enable these things to happen?

Here is my main.java:

package maintest;

public class Main {
    public static void main(String[] args) {
        TestFunctions mf = new TestFunctions();
        try {mf.setUp();} catch (Exception e) {e.printStackTrace();}
        mf.unmarshal();
        mf.setUpPersistence();
        Long id = mf.saveToDatabase();
        System.out.println("hjid is: "+id);
        mf.loadFromDatabase(id);
        mf.marshal();
    }
}

You can read the more lengthy code from TestFunctions.java by clicking on this link. Note that the file sharing site mistakenly center-justifies the code, despite the fact that the code is left-justified on my machine.

persistence.properties is:

hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.username=someusername
hibernate.connection.password=somepassword
hibernate.connection.url=jdbc:mysql://localhost/sometestdatabase
hibernate.hbm2ddl.auto=create-drop
hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider
hibernate.jdbc.batch_size=0  

I am currently getting the following stack trace when I right click Main.java and click run as.. java application:

Exception in thread "main" java.lang.NoClassDefFoundError: maintest/TestFunctions
    at maintest.Main.main(Main.java:7)
Caused by: java.lang.ClassNotFoundException: maintest.TestFunctions
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 1 more   

Here is the directory structure:

Community
  • 1
  • 1
CodeMed
  • 9,527
  • 70
  • 212
  • 364

1 Answers1

2

For your immediate problem: if Main.java resides in src/main/java and needs to call TestFunctions.java, then normal Maven development would put TestFunctions.java in src/main/java and not src/test/java. (It's generally a bad idea to have your "real" code, the stuff in src/main, depending on anything in src/test).

Sbodd
  • 11,279
  • 6
  • 41
  • 42
  • Thank you. +1 for trying to help. I already tried what you suggest. But it just pushes the error message around. Are you willing to look at my other question which shows the result of doing what you suggest? here is the link: http://stackoverflow.com/questions/26347415/inputstream-getresourceasstream-null-pointer-exception – CodeMed Oct 13 '14 at 22:12
  • I think you've basically got the same problem in your other question - you've got stuff in src/main (in that case, TestFunctions.java) trying to access stuff in src/test (in that case, persistence.properties), which won't work; either main, TestFunctions, and persistence.properties all need to be in src/main, or they all need to be in src/test. I'll add an answer to that effect. – Sbodd Oct 14 '14 at 14:15
  • This question asks how to trigger hbm2ddl to create the tables in the MySQL database. It is still not doing that. However, your answer to the other question did solve the other problem, so I marked your other answer as accepted. This question is still unresolved. – CodeMed Oct 14 '14 at 16:55
  • Glad I could get you past the first step. If you update this question with the new behavior you're seeing, I can try to offer further help here. – Sbodd Oct 14 '14 at 17:53
  • Thank you. The new information I am seeing is in a different question because the new information is an incremental step before I can see the hbm2ddl level of it. Here is the link to the current information: http://stackoverflow.com/questions/26366556/no-persistence-provider-for-entitymanager-named-persistence-xml – CodeMed Oct 14 '14 at 17:55