我曾尝试运行 hibernatetool Ant 任务,但一直未成功。Help。这些罐子来自我的 eclipse(3.7.2) 休眠工具插件(3.4)。我得到一个 org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection available 尽管设置了方言
这是我的 build.xml:
<project>
<target name="genero">
<path id="toolslib">
<path location="mylibs/hibernate-tools.jar" />
<path location="mylibs/hibernate3.jar" />
<path location="mylibs/freemarker.jar" />
<path location="mylibs/postgresql-9.0-802.jdbc4.jar" />
<path location="mylibs/dom4j-1.6.1.jar" />
<path location="mylibs/commons-logging-1.0.4.jar" />
<path location="mylibs/slf4j-api-1.5.8.jar" />
<path location="mylibs/slf4j-log4j12-1.5.8.jar" />
<path location="mylibs/log4j-1.2.15.jar" />
<path location="mylibs/cglib-2.2.jar" />
<path location="mylibs/asm.jar" />
<path location="mylibs/commons-collections-3.1.jar" />
<path location="mylibs/slf4j-api-1.5.8.jar" />
</path>
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="toolslib" />
<hibernatetool>
<jdbcconfiguration propertyfile="src/hibernate.cfg.xml" packagename="demo" revengfile="src/hibernate.reveng.xml" />
<hbm2hbmxml destdir="${build.dir}/src" />
<hbm2java jdk5="true" destdir="${build.dir}/src" />
</hibernatetool>
</target>
还有我的 hibernate.cfg.xml:
<?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.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.password">blablabla</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/projteste</property>
<property name="hibernate.connection.username">postgres</property>
</session-factory>
</hibernate-configuration>
和堆栈跟踪:
Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Buildfile: C:\Users\mrtykop\workspace2\testjavahib\build.xml
parsing buildfile C:\Users\mrtykop\workspace2\testjavahib\build.xml with URI = file:/C:/Users/mrtykop/workspace2/testjavahib/build.xml
Project base dir set to: C:\Users\mrtykop\workspace2\testjavahib
Build sequence for target(s) `genero' is [genero]
Complete build sequence is [genero, ]
genero:
parsing buildfile jar:file:/E:/jave/eclipse/plugins/org.apache.ant_1.8.2.v20120109-1030/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/E:/jave/eclipse/plugins/org.apache.ant_1.8.2.v20120109-1030/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
Property "build.dir" has not been set
Property "build.dir" has not been set
[hibernatetool] Executing Hibernate Tool with a JDBC Configuration (for reverse engineering)
[hibernatetool] 1. task: hbm2hbmxml (Generates a set of hbm.xml files)
[hibernatetool] log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
[hibernatetool] log4j:WARN Please initialize the log4j system properly.
[hibernatetool] An exception occurred while running exporter #2:hbm2hbmxml (Generates a set of hbm.xml files)
[hibernatetool] To get the full stack trace run ant with -verbose
[hibernatetool] org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection available
BUILD FAILED
C:\Users\mrtykop\workspace2\testjavahib\build.xml:26: org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection available
at org.hibernate.tool.ant.HibernateToolTask.reportException(HibernateToolTask.java:226)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:189)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
Caused by: org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection available
at org.hibernate.dialect.resolver.DialectFactory.buildDialect(DialectFactory.java:107)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:142)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2163)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2155)
at org.hibernate.cfg.JDBCMetaDataConfiguration.readFromJDBC(JDBCMetaDataConfiguration.java:41)
at org.hibernate.tool.ant.JDBCConfigurationTask.doConfiguration(JDBCConfigurationTask.java:83)
at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:55)
at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:302)
at org.hibernate.tool.ant.HibernateToolTask.getProperties(HibernateToolTask.java:318)
at org.hibernate.tool.ant.ExporterTask.configureExporter(ExporterTask.java:94)
at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:39)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:186)
... 16 more