[英]How to quickly generate persistence.xml from jpa/hibernate classes
It is sometimes tedious to add class names manually to the persistence.xml file for hibernate configuration. 手动将类名添加到persistence.xml文件进行休眠配置有时会很麻烦。 Is there a way to quickly generate the
<class>com.something.Entity1</class>
part of the file? 有没有一种方法可以快速生成文件的
<class>com.something.Entity1</class>
部分?
Found a simple way, using the code from dzone. 使用dzone中的代码找到了一种简单的方法。 And just print them out and copy from the console.
只需打印出来并从控制台复制即可。 Here it is for anyone interested.
这是给任何有兴趣的人的。
Class[] classex = getClasses(Entity1.class.getPackage().getName());
for (Class c : classex) {
if (c.getName().contains("$")) continue;
if (!c.isAnnotationPresent(javax.persistence.Entity.class)) continue;
System.out.println("<class>" + c.getName() + "</class>");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.