我想使用JUnit和Hibernate运行内存数据库HSQLDB,但是当该方法尝试将更改提交到DB时,会出现此异常:(无Spring框架)
Caused by: java.sql.SQLException: invalid schema name: SRH in statement [select liquidacio0_.idLiquidacion as idLiquid1_180_0_, liquidacio0_.fkEstado as fkEstado180_0_, liquidacio0_.FECHA_LIQ as FECHA3_180_0_, liquidacio0_.DIAS_LIQUIDAR as DIAS4_180_0_, liquidacio0_.MES_DIAS as MES5_180_0_, liquidacio0_.MES_LIQUIDACION as MES6_180_0_, liquidacio0_.LIQUIDACION_TVAC as LIQUIDAC7_180_0_, liquidacio0_.FECHA_ESTADO as FECHA8_180_0_, liquidacio0_.fkSolicitud as fkSolici9_180_0_, liquidacio0_.idTvac as idTvac180_0_, liquidacio0_.NUMLIQ as NUMLIQ180_0_, liquidacio0_.legajo as legajo180_0_, liquidacio0_.periodo as periodo180_0_ from srh.srh_liquidacion liquidacio0_ where liquidacio0_.idLiquidacion=?]
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:423)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
此处发生异常:
sesionActiva.getTransaction().commit();
我的hibernateTest.cfg.xml:
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:mem:testdb</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<!--<property name="hibernate.default_schema">srh</property>-->
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">10</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="pkgClasesDeNegocio/pkgAdministracionNovedadAsistencia/Liquidacion.hbm.xml"/>
//And others
</session-factory>
</hibernate-configuration>
我的Liquidacion.hbm.xml:
<hibernate-mapping>
<class catalog="srh" name="pkgClasesDeNegocio.pkgAdministracionNovedadAsistencia.Liquidacion" table="srh_liquidacion">
<id name="idLiquidacion" type="java.lang.Integer">
<column name="idLiquidacion"/>
<generator class="identity"/>
</id>
<many-to-one class="pkgClasesDeNegocio.pkgAdministracionNovedadAsistencia.Estado" lazy="false" fetch="select" name="estado">
<column name="fkEstado" not-null="true"/>
</many-to-one>
<property name="fechaLiquidacion" type="date">
<column length="10" name="FECHA_LIQ"/>
</property>
<property name="cantDiasALiquidar">
<column name="DIAS_LIQUIDAR"/>
</property>
<property name="mesDeDias" type="string">
<column length="50" name="MES_DIAS"/>
</property>
<property name="mesDeLiquidacion" type="string">
<column length="50" name="MES_LIQUIDACION"/>
</property>
<property name="fechaLiquidacionTvac" type="string">
<column length="50" name="LIQUIDACION_TVAC"/>
</property>
<property name="fechaEstado" type="date">
<column length="10" name="FECHA_ESTADO"/>
</property>
<many-to-one class="pkgClasesDeNegocio.pkgAdministracionNovedadAsistencia.SolicitudVacaciones" lazy="false" fetch="select" name="solicitud">
<column name="fkSolicitud" not-null="true"/>
</many-to-one>
<property name="idTvac">
<column name="idTvac"/>
</property>
<property name="nroLiquidacion">
<column name="NUMLIQ"/>
</property>
<property name="legajo">
<column name="legajo"/>
</property>
<property name="periodo">
<column name="periodo"/>
</property>
</class>
答案 0 :(得分:0)
尝试删除catalog =“srh”。这可能是问题所在:http://forums.mysql.com/read.php?39,137564,137629#msg-137629
答案 1 :(得分:0)
将架构名称更改为PUBLIC并且它有效(PUBLIC应该是架构的名称) - ;),所有其他架构名称都不起作用并且给出了“Invalid schema ..name”错误。感谢我在这里找到的旧帖子 https://sourceforge.net/p/unitils/discussion/570578/thread/a887838e/