在Eclipse中安装Hibernate Tools作为插件的正确方法是什么?在Hibernate的网站并没有真正给予任何指示.
看看Hibernate Tools二进制文件HibernateTools-3.2.4.Beta1-R200810311334.zip
,看来我可以在我的eclipse目录中解压缩它.我只是在我的eclipse目录中解压缩它吗?这似乎是一个hacky安装它.
我们正在尝试从Hibernate 3.6.7升级到4.1.2,将Hibernate Tools 3.2.0升级到3.5.0
我们使用Ant生成数据库创建脚本:
<hibernatetool destdir="${target}">
<jpaconfiguration persistenceunit="stdcmpOrderPersistenceUnit" propertyfile="@{propertyfile}"/>
<classpath refid="@{classpathid}"/>
<!-- the file name is relative to $destdir -->
<hbm2ddl outputfilename="@{output}" format="true" export="false" drop="false"/>
</hibernatetool>
Run Code Online (Sandbox Code Playgroud)
我们的持久性单元看起来像这样:
<persistence-unit name="stdcmpOrderPersistenceUnit" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/lakshmi_stdcmp</jta-data-source>
<mapping-file>META-INF/stdcmpOrderNamedQueries.xml</mapping-file>
<class>ch.ethz.id.wai.lakshmi.stdcmp.persistency.PersistentOrder</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.format_sql" value="false"/>
</properties>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)
升级后,我们收到以下错误:
[hibernatetool] org.hibernate.service.jndi.JndiException: Error parsing JNDI name [jdbc/lakshmi_stdcmp]
[hibernatetool] javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
Run Code Online (Sandbox Code Playgroud)
为什么Hibernate会尝试解析JNDI名称,因为PersistenceUnit上的所有信息都可用?我们对旧版本没有任何问题.
在任何情况下,我们如何指定NamingFactory?(哪一个?)
我正在使用Eclipse Luna,我想创建一个Web应用程序并使用Hibernate来获取我的数据.在Eclipse Marketplace中,我找到了用于Indigo或Helios的Hibernate工具,但没有找到Luna.
我找到了Luna的Red Hat JBoss Developper Studio(那是什么?).
任何人都可以告诉我如何强制maven在使用包路径自动生成的hibernate.cfg.xml文件中映射.hbm.xml文件之前?
我的一般想法是,我想通过maven使用hibernate-tools来为我的应用程序生成持久层.所以,我需要hibernate.cfg.xml,然后是所有my_table_names.hbm.xml,最后生成POJO.然而,hbm2java
当我将*.hbm.xml文件放入src/main/resources/package/path/
文件夹但hbm2cfgxml
仅通过表名指定映射文件时,目标将无效,即:
<mapping resource="MyTableName.hbm.xml" />
Run Code Online (Sandbox Code Playgroud)
所以最大的问题是:我如何配置hbm2cfgxml
以便hibernate.cfg.xml如下所示:
<mapping resource="package/path/MyTableName.hbm.xml" />
Run Code Online (Sandbox Code Playgroud)
我的pom.xml目前看起来像这样:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>hbm2cfgxml</id>
<phase>generate-sources</phase>
<goals>
<goal>hbm2cfgxml</goal>
</goals>
<inherited>false</inherited>
<configuration>
<components>
<component>
<name>hbm2cfgxml</name>
<implemetation>jdbcconfiguration</implementation>
<outputDirectory>src/main/resources/</outputDirectory>
</component>
</components>
<componentProperties>
<packagename>package.path</packageName>
<configurationFile>src/main/resources/hibernate.cfg.xml</configurationFile>
</componentProperties>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
然后是第二个问题:有没有办法告诉maven在执行之前将资源复制到目标文件夹hbm2java
?目前我正在使用
mvn clean resources:resources generate-sources
Run Code Online (Sandbox Code Playgroud)
为此,但必须有一个更好的方法.
谢谢你的帮助.
更新:
@Pascal:谢谢你的帮助.现在,映射的路径工作正常,但我不知道之前有什么问题.在从中读取数据库配置时,写入hibernate.cfg.xml可能存在一些问题(尽管文件已更新).
我删除了文件hibernate.cfg.xml,将其替换为database.properties并运行目标hbm2cfgxml
和hbm2hbmxml
.我还没有使用outputDirectory
,也没有configurationfile
在这些目标了.
结果,文件hibernate.cfg.xml
和所有文件*.hbm.xml
都生成到我的target/hibernate3/generated-mappings /文件夹中,这是默认值.然后我hbm2java
用以下内容更新了目标:
<componentProperties>
<packagename>package.name</packagename>
<configurationfile>target/hibernate3/generated-mappings/hibernate.cfg.xml</configurationfile>
</componentProperties>
Run Code Online (Sandbox Code Playgroud)
但后来我得到以下内容: …
我使用Hibernate Tools来生成我的Hibernate POJO映射.
不幸的是,Hibernate工具生成的代码似乎不起作用,我得到了例外
org.hibernate.AnnotationException:Collection既没有泛型类型,也没有OneToMany.targetEntity()
生成异常的代码部分是
/**
* ClassFlag generated by hbm2java
*/
@Entity
@Table(name = "class_flag", catalog = "incbszdb")
public class ClassFlag implements java.io.Serializable {
....
/* HERE */
private Set classFlagI18ns = new HashSet(0);
/* HERE */
public void setClassFlagI18ns(Set classFlagI18ns) {
this.classFlagI18ns = classFlagI18ns;
}
}
Run Code Online (Sandbox Code Playgroud)
根据这篇文章
这篇文章
您必须亲自更改Hibernates生成的代码.
这是我想避免的一件事.任何想法可能是什么问题?
问候
JS
我用这种方式构建我的HibernateUtil:
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from standard (hibernate.cfg.xml) config file.
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Log the exception.
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
Run Code Online (Sandbox Code Playgroud)
因此,当我尝试在Eclipse中的HQL编辑器中执行HQL命令(使用Hibernate Tools)时,会出现以下错误:
为什么会这样?它不会通过ConfigureAnnotation更改AnnotationConfiguration?
UPDATE
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password"><password></property>
<property name="hibernate.connection.url">jdbc:mysql://<hostname>:3306/<schema></property>
<property …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Hibernate Tools对SQL Server 2005进行逆向工程,并且遇到一个奇怪的错误:
org.hibernate.cfg.JDBCBinderException:
Duplicate class name 'CheckConstraints' generated for
'org.hibernate.mapping.Table(e2rm_maintenance_development2.sys.check_constraints??)'.
Same name where generated for
'org.hibernate.mapping.Table(e2rm_maintenance_development2.sys.check_constraints??)'
Duplicate class name 'CheckConstraints' generated for
'org.hibernate.mapping.Table(e2rm_maintenance_development2.sys.check_constraints??)'.
Same name where generated for
'org.hibernate.mapping.Table(e2rm_maintenance_development2.sys.check_constraints??)'
Run Code Online (Sandbox Code Playgroud) 所以我试图使用Hibernate Tools来反向工程我的数据库,我只是开始使用Freemarker模板来弱化它生成的代码.问题是我想更改它生成的DAO类的名称.默认情况下,DAO类的形式PersonHome中名为然而,名称更改为的PersonDAO我修改了DAO/daohome.ftl.
虽然这确实将生成的类名更改为PersonDAO,但java文件仍称为PersonHome.java.
有没有我可以更改生成的文件名以匹配源代码的地方?
java hibernate freemarker reverse-engineering hibernate-tools
我可以知道Eclipse插件Hibernate工具可以用来生成JPA实体@entity吗?生成的Java文件如下所示,而不是JPA:
package com.test.only.model;
// Generated Jul 19, 2011 12:13:40 PM by Hibernate Tools 3.2.0.CR1
import java.math.BigDecimal;
import java.util.Date;
/**
* Account generated by hbm2java
*/
public class Account implements java.io.Serializable {
Run Code Online (Sandbox Code Playgroud) 我使用Eclipse Hibernate Tools从我的数据库开始创建域类,并需要添加JPA注释.
有没有办法添加注释?可能有reveng.xml和逆向工程?该怎么做?
生成的域代码:
public class Country implements java.io.Serializable {
private long id;
private String description;
private String identifier;
private String futureuse;
private Set accounts = new HashSet(0);
public Country() {
}
public Country(long id, String description, String identifier) {
this.id = id;
this.description = description;
this.identifier = identifier;
}
...
Run Code Online (Sandbox Code Playgroud)
需要的代码:
@Entity
@Table(name = "COUNTRY")
public class Country implements java.io.Serializable {
@Id
@Column(name="CNTR_ID")
private Long id;
@Column(name="CNTR_FUTUREUSE")
private String futureUse;
@Column(name="CNTR_IDENTIFIER")
private String identifier;
@Column(name="CNTR_DESCRIPTION")
private String description; …
Run Code Online (Sandbox Code Playgroud) hibernate ×10
hibernate-tools ×10
eclipse ×4
java ×4
annotations ×2
freemarker ×1
jboss-tools ×1
jpa ×1
maven-2 ×1
object ×1
sql-server ×1