persisting hyperjaxb-generated entities to mysql from eclipse

久未见 提交于 2019-12-02 15:39:31

问题


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:


回答1:


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).



来源:https://stackoverflow.com/questions/26348480/persisting-hyperjaxb-generated-entities-to-mysql-from-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!