Hibernate hbm.xml id标记生成器属性不起作用



我正在尝试构建一个Hibernate项目。我的问题就像标题一样。我得到了一个hibernate映射xml类,该类由ant进程构建。

我还想让你看看我的配置文件dtd。在我国,很少有人使用这个框架,所以这里没有太多参考文献。(我读了一本2009年出版的书。它的目标是休眠3.X(

我将附加我的ant构建文件、配置文件、映射文件、执行文件和错误日志。

这是我的build.xml(蚂蚁(

<?xml version="1.0" encoding="UTF-8"?>
<project name="HibernateEx2" default="db" basedir="."
    xmlns:artifact="antlib:org.apache.maven.artifact.ant">
    <property name="source.root" value="src"/>
    <property name="class.root" value="classpath"/>
    <property name="data.dir" value="data"/>
    <artifact:dependencies pathId="dependency.classpath">
        <dependency groupId="hsqldb" artifactId="hsqldb" version="1.8.0.10"/>
        <dependency groupId="org.hibernate" artifactId="hibernate-core" version="4.3.10.Final">
            <exclusion groupId="javax.transaction" artifactId="jta"/>
        </dependency>
        <!-- 3.2.4.GA - After hibernate4 need upgrade hibernate-tools -->
        <dependency groupId="org.hibernate" artifactId="hibernate-tools" version="4.3.1.CR1"/>
        <dependency groupId="org.apache.geronimo.specs" artifactId="geronimo-jta_1.1_spec" version="1.1.1"/>
        <!-- java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory -->
        <dependency groupId="commons-logging" artifactId="commons-logging" version="1.2"/>
        <dependency groupId="log4j" artifactId="log4j" version="1.2.17"/>
        <!-- java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder -->
        <dependency groupId="org.slf4j" artifactId="slf4j-log4j12" version="1.7.12"/>   
    </artifact:dependencies>
    <path id="project.class.path">
        <pathelement location="${class.root}"/>
        <path refid="dependency.classpath" />
    </path>
    <!-- Explaining how to use hibernate -->
    <taskdef name="hibernatetool" 
        classname="org.hibernate.tool.ant.HibernateToolTask"
        classpathref="project.class.path"/>
    <target name="db" description="Run HSQLDB database management UI against the database file -- use when application is not running">
        <java classname="org.hsqldb.util.DatabaseManager" fork="yes">
            <classpath refid="project.class.path"/>
            <arg value="-driver"/>
            <arg value="org.hsqldb.jdbcDriver"/>
            <arg value="-url"/>
            <arg value="jdbc:hsqldb:${data.dir}/music/"/>
            <arg value="-user"/>
            <arg value="sa"/>
        </java>
    </target>
    <target name="print-classpath" description="Show the dependency class path">
        <property name="class.path" refid="dependency.classpath"/>
        <echo>${class.path}</echo>
    </target>
    <!-- Generate java code -->
    <target name="codegen" description="Generate Java source from the OR mapping files">
        <hibernatetool destdir="${source.root}">
            <configuration configurationfile="${source.root}/hibernate.cfg.xml"/>
            <hbm2java/>
        </hibernatetool>
    </target>
    <!-- Creating Sub drectories -->
    <target name="prepare" description="Set up build structures">
        <mkdir dir="${class.root}"/>
        <copy todir="${class.root}">
            <fileset dir="${source.root}">
                <include name="**/*.properties"/>
                <include name="**/*.xml"/>
            </fileset>
        </copy>
    </target>
    <!-- Creating Schema for mapping files -->
    <target name="schema" depends="prepare" description="Generate DB schema from the OR mappinf files">
        <hibernatetool destdir="${source.root}">
            <configuration configurationfile="${source.root}/hibernate.cfg.xml"/>
            <hbm2ddl drop="yes"/>
        </hibernatetool>
    </target>

    <!-- Compile Java -->
    <!-- added includeantruntime="false" to javac, since terminal compile warning -->
    <target name="compile" depends="prepare" description="Compiles all java classes">
        <javac srcdir="${source.root}" destdir="${class.root}" 
            debug="on" optimize="off" deprecation="on" includeantruntime="true">
            <classpath refid="project.class.path"/>
        </javac>
    </target>
    <target name="ctest" depends="compile" description="Creates and persists some sample data">
        <java classname="org.owls.ht.CreateTest" fork="true">
            <classpath refid="project.class.path"/>
        </java>
    </target>
    <target name="qtest" description="Run a simple Hibernate query" depends="compile">
        <java classname="org.owls.ht.QueryTest" fork="true">
            <classpath refid="project.class.path"/>
        </java>
    </target>
</project>

休眠配置文件hibernate.cfg.xml。虽然我的项目包括hibernate-core 4.3.10.final,但使用3.0DTD看起来非常可疑。

<?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="dialect">org.hibernate.dialect.HSQLDialect</property>
        <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="connection.url">jdbc:hsqldb:data/music</property>
        <property name="connection.username">sa</property>
        <property name="connection.password"></property>
        <property name="connection.shutdown">true</property>
        <!-- Connection Pool -->
        <property name="connection.pool_size">1</property>
        <!-- Hibernate Session Manager Activate -->
        <property name="current_session_context_class">thread</property>
        <!-- Unable Cache -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <!-- Batch service unable -->
        <property name="jdbc.batch_size">0</property>
        <property name="show_sql">true</property>
        <!-- Mapping documents -->
        <mapping resource="org/owls/ht/data/Track.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

映射文件。我认为id部分不起作用,尤其是<generator="native"/>部分。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hiberbate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="org.owls.ht.data.Track" table="TRACK">
        <meta attribute="class-description">
            Playable Track list
            @author juneyoungoh
        </meta>
        <id name="id" type="int" column="TRACK_ID">
            <meta attribute="scope-set">protected</meta>
            <generator class="native"/>
        </id>
        <property name="title" type="string" not-null="true"/>
        <property name="filePath" type="string" not-null="true"/>
        <property name="playTime" type="time">
            <meta attribute="field-description">Duration</meta>
        </property>
        <property name="added" type="date">
            <meta attribute="field-description">Created</meta>
        </property>
        <property name="volume" type="short" not-null="true">
            <meta attribute="field-description">Volume</meta>
        </property>
    </class>
</hibernate-mapping>

这是输出,Track.java

package org.owls.ht.data;
// Generated Jul 13, 2015 3:47:01 PM by Hibernate Tools 4.3.1

import java.util.Date;
/**
 *          Playable Track list
 *          @author juneyoungoh
 *      
 */
public class Track  implements java.io.Serializable {

     private int id;
     private String title;
     private String filePath;
     /**
      * Duration
     */
     private Date playTime;
     /**
      * Created
     */
     private Date added;
     /**
      * Volume
     */
     private short volume;
    public Track() {
    }

    public Track(String title, String filePath, short volume) {
        this.title = title;
        this.filePath = filePath;
        this.volume = volume;
    }
    public Track(String title, String filePath, Date playTime, Date added, short volume) {
       this.title = title;
       this.filePath = filePath;
       this.playTime = playTime;
       this.added = added;
       this.volume = volume;
    }
    public int getId() {
        return this.id;
    }
    protected void setId(int id) {
        this.id = id;
    }
    public String getTitle() {
        return this.title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getFilePath() {
        return this.filePath;
    }
    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }
    /**       
     *      * Duration
     */
    public Date getPlayTime() {
        return this.playTime;
    }
    public void setPlayTime(Date playTime) {
        this.playTime = playTime;
    }
    /**       
     *      * Created
     */
    public Date getAdded() {
        return this.added;
    }
    public void setAdded(Date added) {
        this.added = added;
    }
    /**       
     *      * Volume
     */
    public short getVolume() {
        return this.volume;
    }
    public void setVolume(short volume) {
        this.volume = volume;
    }


}

这是我的测试类,它包含main方法。

package org.owls.ht;
import java.sql.Time;
import java.util.Date;
import org.hibernate.*;
import org.hibernate.cfg.Configuration;
import org.owls.ht.data.Track;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.service.ServiceRegistry;

public class CreateTest {
    private static Track makingTrack(String title, String filePath, Date playTime){
        Track tmp = new Track(title, filePath, playTime, new Date(), (short)0);
        return tmp;
    }
    public static void main(String[] args) throws Exception {

        Configuration config = new Configuration();
        config.configure();
        ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
                config.getProperties()).build();
        SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
        Session session = sessionFactory.openSession();
        Transaction tx = null;
        try{
            tx = session.beginTransaction();
            session.save(makingTrack("Russian Trance"
                    , "vol2/album610/track02.mp3", Time.valueOf("00:03:30")));
            session.save(makingTrack("Video Killed the Radio Star"
                    , "vol2/album611/track12.mp3", Time.valueOf("00:03:49")));
            session.save(makingTrack("Gravity's Angel"
                    , "vol2/album175/track03.mp3", Time.valueOf("00:06:06")));
            tx.commit();
        } catch (Exception e){
            if(tx != null) {
                tx.rollback();
            } 
            throw new Exception("Transaction failed", e);
        } finally{
            session.close();
        }
        sessionFactory.close();
    }
};

//====================================

终于!这是我通过ant命令运行此代码时的错误消息。

Buildfile: /Users/juneyoungoh/Documents/workplaceJava1/HibernateEx3/build.xml
prepare:
compile:
    [javac] Compiling 2 source files to /Users/juneyoungoh/Documents/workplaceJava1/HibernateEx3/classpath
ctest:
     [java] 15:50:01,618  INFO Version:66 -HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
     [java] 15:50:01,643  INFO Version:54 -HHH000412: Hibernate Core {4.3.10.Final}
     [java] 15:50:01,651  INFO Environment:224 -HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.username=sa, hibernate.connection.password=****, hibernate.dialect=org.hibernate.dialect.HSQLDialect, hibernate.connection.shutdown=true, hibernate.connection.url=jdbc:hsqldb:data/music, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.driver_class=org.hsqldb.jdbcDriver}
     [java] 15:50:01,656  INFO Environment:346 -HHH000021: Bytecode provider name : javassist
     [java] 15:50:01,693  INFO Configuration:2075 -HHH000043: Configuring from resource: /hibernate.cfg.xml
     [java] 15:50:01,693  INFO Configuration:2094 -HHH000040: Configuration resource: /hibernate.cfg.xml
     [java] 15:50:01,814  WARN DTDEntityResolver:75 -HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
     [java] 15:50:01,882  INFO Configuration:759 -HHH000221: Reading mappings from resource: org/owls/ht/data/Track.hbm.xml
     [java] 15:50:01,938  WARN DTDEntityResolver:75 -HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
     [java] 15:50:02,004  INFO Configuration:2216 -HHH000041: Configured SessionFactory: null
     [java] 15:50:02,190  WARN DriverManagerConnectionProviderImpl:93 -HHH000402: Using Hibernate built-in connection pool (not for production use!)
     [java] 15:50:02,193  INFO DriverManagerConnectionProviderImpl:166 -HHH000401: using driver [org.hsqldb.jdbcDriver] at URL [jdbc:hsqldb:data/music]
     [java] 15:50:02,194  INFO DriverManagerConnectionProviderImpl:175 -HHH000046: Connection properties: {user=sa, password=****, shutdown=true}
     [java] 15:50:02,194  INFO DriverManagerConnectionProviderImpl:180 -HHH000006: Autocommit mode: false
     [java] 15:50:02,196  INFO DriverManagerConnectionProviderImpl:102 -HHH000115: Hibernate connection pool size: 1 (min=1)
     [java] 15:50:02,585  INFO Dialect:145 -HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect
     [java] 15:50:02,607  INFO LobCreatorBuilder:97 -HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
     [java] 15:50:02,700  INFO TransactionFactoryInitiator:62 -HHH000399: Using default transaction strategy (direct JDBC transactions)
     [java] 15:50:02,705  INFO ASTQueryTranslatorFactory:47 -HHH000397: Using ASTQueryTranslatorFactory
     [java] Exception in thread "main" java.lang.Exception: Transaction failed
     [java]     at org.owls.ht.CreateTest.main(CreateTest.java:50)
     [java] Caused by: org.hibernate.exception.GenericJDBCException: could not prepare statement
     [java]     at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
     [java]     at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
     [java]     at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:196)
     [java]     at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareStatement(StatementPreparerImpl.java:122)
     [java]     at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:55)
     [java]     at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3032)
     [java]     at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3558)
     [java]     at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:98)
     [java]     at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:492)
     [java]     at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:197)
     [java]     at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:181)
     [java]     at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:216)
     [java]     at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:334)
     [java]     at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:289)
     [java]     at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:195)
     [java]     at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:126)
     [java]     at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:209)
     [java]     at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
     [java]     at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:194)
     [java]     at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
     [java]     at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
     [java]     at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:715)
     [java]     at org.hibernate.internal.SessionImpl.save(SessionImpl.java:707)
     [java]     at org.hibernate.internal.SessionImpl.save(SessionImpl.java:702)
     [java]     at org.owls.ht.CreateTest.main(CreateTest.java:36)
     [java] Caused by: java.sql.SQLException: This function is not supported
     [java]     at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
     [java]     at org.hsqldb.jdbc.Util.notSupported(Unknown Source)
     [java]     at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
     [java]     at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$2.doPrepare(StatementPreparerImpl.java:124)
     [java]     at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:186)
     [java]     ... 22 more
     [java] Hibernate: insert into TRACK (TRACK_ID, title, filePath, playTime, added, volume) values (null, ?, ?, ?, ?, ?)
     [java] 15:50:03,322  WARN SqlExceptionHelper:144 -SQL Error: -20, SQLState: IM001
     [java] 15:50:03,323 ERROR SqlExceptionHelper:146 -This function is not supported

我有两个可疑部分。

  1. 在消息CCD_ 8。为什么会话工厂为空
  2. [java] Hibernate: insert into TRACK (TRACK_ID, title, filePath, playTime, added, volume) values (null, ?, ?, ?, ?, ?)。这段代码似乎试图将空值放入ID字段。但是,由于我放置了<generator class="native"/>,所以它不应该为null。对吧

感谢您的回答:D

这不是一个答案,但有字符限制。

//===编辑#1

我已经更改了hsqldb的依赖关系,错误消息也已更改。我引用了这篇文章:脚本文件行出错:1意外的令牌UNIQUE,需要语句[SET DATABASE UNIQUE]中的COLLATION

这里的前一个代码(它是build.xml的一部分(

<dependency groupId="hsqldb" artifactId="hsqldb" version="1.8.0.10"/>

这是一个新的。

<dependency groupId="org.hsqldb" artifactId="hsqldb" version="2.3.3"/>

现在,它似乎取得了成功,但仍然存在连接问题。日志如下。

Buildfile: /Users/juneyoungoh/Documents/workplaceJava1/HibernateEx3/build.xml
prepare:
codegen:
[hibernatetool] Executing Hibernate Tool with a Standard Configuration
[hibernatetool] 1. task: hbm2java (Generates a set of .java files)
[hibernatetool] SLF4J: The requested version 1.6.99 by your slf4j binding is not compatible with [1.5.5, 1.5.6, 1.5.7, 1.5.8]
[hibernatetool] SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
[hibernatetool] 16:38:13,283  INFO Version:66 -HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
[hibernatetool] 16:38:13,303  INFO Version:54 -HHH000412: Hibernate Core {4.3.10.Final}
[hibernatetool] 16:38:13,308  INFO Environment:224 -HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.username=sa, hibernate.connection.password=****, hibernate.dialect=org.hibernate.dialect.HSQLDialect, hibernate.connection.shutdown=true, hibernate.connection.url=jdbc:hsqldb:data/music, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.driver_class=org.hsqldb.jdbcDriver}
[hibernatetool] 16:38:13,309  INFO Environment:346 -HHH000021: Bytecode provider name : javassist
[hibernatetool] 16:38:13,353  INFO Configuration:2133 -HHH000042: Configuring from file: hibernate.cfg.xml
[hibernatetool] 16:38:13,408  WARN DTDEntityResolver:75 -HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
[hibernatetool] 16:38:13,448  INFO Configuration:759 -HHH000221: Reading mappings from resource: org/owls/ht/data/Track.hbm.xml
[hibernatetool] 16:38:13,535  WARN DTDEntityResolver:75 -HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
[hibernatetool] 16:38:13,624  INFO Configuration:2216 -HHH000041: Configured SessionFactory: null
[hibernatetool] 16:38:13,951  INFO Version:15 -Hibernate Tools 4.3.1
prepare:
schema:
[hibernatetool] Executing Hibernate Tool with a Standard Configuration
[hibernatetool] 1. task: hbm2ddl (Generates database schema)
[hibernatetool] 16:38:14,618  INFO Configuration:2133 -HHH000042: Configuring from file: hibernate.cfg.xml
[hibernatetool] 16:38:14,621  WARN DTDEntityResolver:75 -HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
[hibernatetool] 16:38:14,626  INFO Configuration:759 -HHH000221: Reading mappings from resource: org/owls/ht/data/Track.hbm.xml
[hibernatetool] 16:38:14,631  WARN DTDEntityResolver:75 -HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
[hibernatetool] 16:38:14,653  INFO Configuration:2216 -HHH000041: Configured SessionFactory: null
[hibernatetool] 16:38:14,869  WARN DriverManagerConnectionProviderImpl:93 -HHH000402: Using Hibernate built-in connection pool (not for production use!)
[hibernatetool] 16:38:14,878  INFO DriverManagerConnectionProviderImpl:166 -HHH000401: using driver [org.hsqldb.jdbcDriver] at URL [jdbc:hsqldb:data/music]
[hibernatetool] 16:38:14,879  INFO DriverManagerConnectionProviderImpl:175 -HHH000046: Connection properties: {user=sa, password=****, shutdown=true}
[hibernatetool] 16:38:14,879  INFO DriverManagerConnectionProviderImpl:180 -HHH000006: Autocommit mode: false
[hibernatetool] 16:38:14,883  INFO DriverManagerConnectionProviderImpl:102 -HHH000115: Hibernate connection pool size: 1 (min=1)
[hibernatetool] 16:38:15,963  INFO Dialect:145 -HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect
[hibernatetool] 16:38:16,018  INFO SchemaExport:344 -HHH000227: Running hbm2ddl schema export
[hibernatetool] 16:38:16,019 DEBUG SchemaExport:354 -Import file not found: /import.sql
[hibernatetool] Hibernate: drop table TRACK if exists
[hibernatetool] drop table TRACK if exists;
[hibernatetool] Hibernate: create table TRACK (TRACK_ID integer generated by default as identity (start with 1), title varchar(255) not null, filePath varchar(255) not null, playTime time, added date, volume smallint not null, primary key (TRACK_ID))
[hibernatetool] create table TRACK (TRACK_ID integer generated by default as identity (start with 1), title varchar(255) not null, filePath varchar(255) not null, playTime time, added date, volume smallint not null, primary key (TRACK_ID));
[hibernatetool] 16:38:16,031  INFO SchemaExport:406 -HHH000230: Schema export complete
prepare:
compile:
    [javac] Compiling 2 source files to /Users/juneyoungoh/Documents/workplaceJava1/HibernateEx3/classpath
ctest:
     [java] 16:38:18,171  INFO Version:66 -HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
     [java] 16:38:18,186  INFO Version:54 -HHH000412: Hibernate Core {4.3.10.Final}
     [java] 16:38:18,191  INFO Environment:224 -HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.username=sa, hibernate.connection.password=****, hibernate.dialect=org.hibernate.dialect.HSQLDialect, hibernate.connection.shutdown=true, hibernate.connection.url=jdbc:hsqldb:data/music, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.driver_class=org.hsqldb.jdbcDriver}
     [java] 16:38:18,200  INFO Environment:346 -HHH000021: Bytecode provider name : javassist
     [java] 16:38:18,258  INFO Configuration:2075 -HHH000043: Configuring from resource: /hibernate.cfg.xml
     [java] 16:38:18,258  INFO Configuration:2094 -HHH000040: Configuration resource: /hibernate.cfg.xml
     [java] 16:38:18,367  WARN DTDEntityResolver:75 -HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
     [java] 16:38:18,417  INFO Configuration:759 -HHH000221: Reading mappings from resource: org/owls/ht/data/Track.hbm.xml
     [java] 16:38:18,496  WARN DTDEntityResolver:75 -HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
     [java] 16:38:18,567  INFO Configuration:2216 -HHH000041: Configured SessionFactory: null
     [java] 16:38:18,774  WARN DriverManagerConnectionProviderImpl:93 -HHH000402: Using Hibernate built-in connection pool (not for production use!)
     [java] 16:38:18,779  INFO DriverManagerConnectionProviderImpl:166 -HHH000401: using driver [org.hsqldb.jdbcDriver] at URL [jdbc:hsqldb:data/music]
     [java] 16:38:18,779  INFO DriverManagerConnectionProviderImpl:175 -HHH000046: Connection properties: {user=sa, password=****, shutdown=true}
     [java] 16:38:18,780  INFO DriverManagerConnectionProviderImpl:180 -HHH000006: Autocommit mode: false
     [java] 16:38:18,782  INFO DriverManagerConnectionProviderImpl:102 -HHH000115: Hibernate connection pool size: 1 (min=1)
     [java] Exception in thread "main" org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
     [java]     at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.convert(BasicConnectionCreator.java:122)
     [java]     at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:140)
     [java]     at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:58)
     [java]     at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:75)
     [java]     at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:106)
     [java]     at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
     [java]     at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
     [java]     at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
     [java]     at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)
     [java]     at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)
     [java]     at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
     [java]     at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
     [java]     at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
     [java]     at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887)
     [java]     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
     [java]     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930)
     [java]     at org.owls.ht.CreateTest.main(CreateTest.java:30)
     [java] Caused by: java.sql.SQLException: Database lock acquisition failure: lockFile: org.hsqldb.persist.LockFile@6d7cf6af[file =/Users/juneyoungoh/Documents/workplaceJava1/HibernateEx3/data/music.lck, exists=true, locked=false, valid=false, ] method: checkHeartbeat read: 2015-07-13 07:38:28 heartbeat - read: -2877 ms.
     [java]     at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
     [java]     at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
     [java]     at org.hsqldb.jdbc.JDBCConnection.<init>(Unknown Source)
     [java]     at org.hsqldb.jdbc.JDBCDriver.getConnection(Unknown Source)
     [java]     at org.hsqldb.jdbc.JDBCDriver.connect(Unknown Source)
     [java]     at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:55)
     [java]     ... 14 more
     [java] Caused by: org.hsqldb.HsqlException: Database lock acquisition failure: lockFile: org.hsqldb.persist.LockFile@6d7cf6af[file =/Users/juneyoungoh/Documents/workplaceJava1/HibernateEx3/data/music.lck, exists=true, locked=false, valid=false, ] method: checkHeartbeat read: 2015-07-13 07:38:28 heartbeat - read: -2877 ms.
     [java]     at org.hsqldb.error.Error.error(Unknown Source)
     [java]     at org.hsqldb.error.Error.error(Unknown Source)
     [java]     at org.hsqldb.persist.LockFile.newLockFileLock(Unknown Source)
     [java]     at org.hsqldb.persist.Logger.acquireLock(Unknown Source)
     [java]     at org.hsqldb.persist.Logger.open(Unknown Source)
     [java]     at org.hsqldb.Database.reopen(Unknown Source)
     [java]     at org.hsqldb.Database.open(Unknown Source)
     [java]     at org.hsqldb.DatabaseManager.getDatabase(Unknown Source)
     [java]     at org.hsqldb.DatabaseManager.newSession(Unknown Source)
     [java]     ... 18 more
     [java] Java Result: 1
BUILD SUCCESSFUL
Total time: 19 seconds

这是所有这些问题的总结。

  1. this function is not supported-->我不知道为什么,但我可以通过。。。a。从构建路径中删除Maven存储库(我被迫将其包括在内,因为我想在eclipse中使用auto-corcelete函数(。b。将hsqlsb依赖关系版本从1.8.0.10更改为2.3.3(请注意,我也更改了groupId(
  2. Error calling Driver#connect-->当存在2个以上的hsqldb实例时,会发生这种情况。(这个很确定(当我在终端中键入ps -ef | grep 'java'时,我可以确认有2个hsqldb进程。我杀了那些之后,蚂蚁建造成功了

谢谢。尽管我得到了答案,但我仍然想要这个问题的更具体的答案。如果发布了更好的答案,我会选择:D

相关内容

  • 没有找到相关文章

最新更新