从eclipse持久化hyperjaxb生成的实体到mysql [英] persisting hyperjaxb-generated entities to mysql from eclipse

查看:126
本文介绍了从eclipse持久化hyperjaxb生成的实体到mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 hyperjaxb rel =nofollow noreferrer>本教程。到目前为止,我已经得到了 marshal unmarshal ,但它还没有触发 hbm2ddl 在数据库中创建表,并且不清楚在eclipse目录结构中,我应该找到 Main.java TestFunctions.java 我创建的类,以从上面的教程链接运行代码。

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?

这是我的main.java:

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();
    }
}

您可以从 TestFunctions.java 点击此链接 。请注意,文件共享站点错误地对准代码,尽管代码在我的机器上是对齐的。

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 是:

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  

我正在得到当我右键单击 Main.java 并单击运行as。java应用程序

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   

这是目录结构:

img src =https://s11.postimg.org/bag9abbf7/directorystructure.jpg>

推荐答案

:如果 Main.java 驻留在 src / main / java 中,需要调用 TestFunctions。 java ,那么正常的Maven开发将在 src / main / java 中放入 TestFunctions.java 而不是 src / test / java 。 (根据 src / test src / main 中的内容通常是一个坏主意c $ c>)。

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

这篇关于从eclipse持久化hyperjaxb生成的实体到mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆