Hi All,
I have two tables, "Equipamento" and "Peca" mapped as follow.
The Equipamento is parent in the database many to many relationship that isn't present in the mapped file, since it is comment out.
If I comment out the reference to "Peca" in my hibenate.cfg.xml I receive "Equipamento" OK. But if I uncommented "Peca", the hibernate tries to get it from database raising an error even there isn't any reference for.
I'd tried to run in hibernate 2.0 and 3.0 with the same results.
What I'm doing wrong?
Please, any help is appreciated,
Ivan Saraiva
=====================
method Session.run
=====================
public void run(Session session) throws HibernateException {
String hql = "from Equipamento where " +
"id_empresa = ? and " +
"# = ? and action <> 'D'";
Object[] fields = new Object[2];
fields[0] = equipamento.getIdEmpresa();
NullableType[] types = {Hibernate.INTEGER,
Hibernate.STRING};
if(equipamento.getPatrimonio() != null) {
hql = hql.replaceAll("#", "patrimonio");
fields[1] = equipamento.getPatrimonio();
}
else {
hql = hql.replaceAll("#", "numeroSerie");
fields[1] = equipamento.getNumeroSerie();
}
System.err.println("hql="+hql);
equipamentos = session.find(hql,
fields,
types);
session.clear();
}
}
=====================
Equipamento
=====================
<class name="Equipamento" table="Equipamento">
<id name="idEquipamento" column="id_equipamento" type="java.lang.Integer">
<generator class="native"/>
</id>
<property name="idEmpresa" column="id_empresa" type="java.lang.Integer" />
<property name="idDepto" column="id_Depto" type="java.lang.Integer" not-null="true" />
<property name="codStatus" column="cod_Status" type="java.lang.Integer" not-null="true" />
<property name="userId" column="User_Id" type="java.lang.Integer" not-null="true" />
<property name="idModelo" column="id_Modelo" type="java.lang.Integer" not-null="true" />
<property name="idContato" column="id_contato" type="java.lang.Integer" not-null="true" />
<property name="ehBackup" column="ehBackup" type="java.lang.Byte" not-null="true" />
<property name="numeroSerie" column="numeroSerie" type="java.lang.String" not-null="true" />
<property name="garantia" column="garantia" type="java.lang.String" not-null="true" />
<property name="patrimonio" column="patrimonio" type="java.lang.String" />
<property name="action" column="Action" type="java.lang.String" not-null="true" />
<property name="modifiedDate" column="Modified_Date" type="java.util.Date" not-null="true" />
<many-to-one name="contrato" column="id_contrato" class="Contrato" not-null="true" />
<!--
<set
lazy="true"
name="pecas"
table="EquipamentoPeca"
cascade="save-update">
<key column="id_Equipamento" />
<many-to-many class="Peca" column="id_Peca"/>
</set>
-->
</class>
=====================
Peca
=====================
<class name="Peca" table="Peca">
<id name="idPeca" column="id_peca" type="java.lang.Integer">
<generator class="native"/>
</id>
<property name="descricao" column="descricao" type="java.lang.String" not-null="true" />
<property name="idModelo" column="id_Modelo" type="java.lang.Integer" not-null="true" />
<property name="userId" column="User_Id" type="java.lang.Integer" not-null="true" />
<property name="idEmpresa" column="id_empresa" type="java.lang.Integer" not-null="true" />
<property name="codigoPeca" column="codigo_peca" type="java.lang.String" not-null="true" />
<property name="action" column="Action" type="java.lang.String" not-null="true" />
<property name="modifiedDate" column="Modified_Date" type="java.util.Date" not-null="true" />
</class>
=====================
my hibernate.cfg.xml:
=====================
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<hibernate-configuration>
<session-factory>
<!-- Connection properties -->
<property name="show-sql">true</property>
<property name="connection.username">sa</property>
<property name="connection.url">jdbc:microsoft:sqlserver://piratasoft:1433;databasename=s10;SelectMethod=Cursor</property>
<property name="dialect">net.sf.hibernate.dialect.SQLServerDialect</property>
<property name="connection.password">ac4972wk</property>
<property name="connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<!--
<property name="connection.driver_class">com.microsoft.jdbcx.sqlserver.SQLServerDataSource</property>
-->
<!-- Connection Pool properties -->
<property name="c3p0.min_size">5</property>
<property name="c3p0.max_size">20</property>
<property name="c3p0.timeout">300</property>
<property name="c3p0.max_statements">50</property>
<property name="c3p0.idle_test_period">3000</property>
<!-- mapping files -->
<mapping resource="com/dedalus/db/hibernate/Cliente.hbm.xml"/>
<mapping resource="com/dedalus/db/hibernate/Contrato.hbm.xml"/>
<mapping resource="com/dedalus/db/hibernate/Empresa.hbm.xml"/>
<mapping resource="com/dedalus/db/hibernate/Equipamento.hbm.xml"/>
<mapping resource="com/dedalus/db/hibernate/Fabricante.hbm.xml"/>
<mapping resource="com/dedalus/db/hibernate/Fornecedor.hbm.xml"/>
<mapping resource="com/dedalus/db/hibernate/Funcao.hbm.xml"/>
<mapping resource="com/dedalus/db/hibernate/Perfil.hbm.xml"/>
<!--
<mapping resource="com/dedalus/db/hibernate/Peca.hbm.xml"/>
-->
<mapping resource="com/dedalus/db/hibernate/Software.hbm.xml"/>
<mapping resource="com/dedalus/db/hibernate/StatusContrato.hbm.xml"/>
<mapping resource="com/dedalus/db/hibernate/TipoBackup.hbm.xml"/>
<mapping resource="com/dedalus/db/hibernate/TipoPessoa.hbm.xml"/>
<mapping resource="com/dedalus/db/hibernate/TipoRepasse.hbm.xml"/>
<mapping resource="com/dedalus/db/hibernate/Usuario.hbm.xml"/>
</session-factory>
</hibernate-configuration>
=====================
Excerpt from from error log
=====================
201891 [http-8080-Processor21] DEBUG net.sf.hibernate.hql.QueryTranslator - HQL: from com.dedalus.db.hibernate.Equipamento where id_empresa = ? and patrimonio = ? and action <> 'D'
201891 [http-8080-Processor21] DEBUG net.sf.hibernate.hql.QueryTranslator - SQL: select equipament0_.id_equipamento as id_equip1_, equipament0_.id_empresa as id_empresa, equipament0_.id_Depto as id_Depto, equipament0_.cod_Status as cod_Status, equipament0_.User_Id as User_Id, equipament0_.id_Modelo as id_Modelo, equipament0_.id_contato as id_contato, equipament0_.ehBackup as ehBackup, equipament0_.numeroSerie as numeroSe9_, equipament0_.garantia as garantia, equipament0_.patrimonio as patrimonio, equipament0_.Action as Action, equipament0_.Modified_Date as Modifie13_, equipament0_.id_contrato as id_cont14_ from Equipamento equipament0_ where (id_empresa=? )and(patrimonio=? )and(action<>'D' )
201891 [http-8080-Processor21] DEBUG net.sf.hibernate.impl.BatcherImpl - about to open: 0 open PreparedStatements, 0 open ResultSets
201891 [http-8080-Processor21] DEBUG net.sf.hibernate.SQL - select equipament0_.id_equipamento as id_equip1_, equipament0_.id_empresa as id_empresa, equipament0_.id_Depto as id_Depto, equipament0_.cod_Status as cod_Status, equipament0_.User_Id as User_Id, equipament0_.id_Modelo as id_Modelo, equipament0_.id_contato as id_contato, equipament0_.ehBackup as ehBackup, equipament0_.numeroSerie as numeroSe9_, equipament0_.garantia as garantia, equipament0_.patrimonio as patrimonio, equipament0_.Action as Action, equipament0_.Modified_Date as Modifie13_, equipament0_.id_contrato as id_cont14_ from Equipamento equipament0_ where (id_empresa=? )and(patrimonio=? )and(action<>'D' )
201891 [http-8080-Processor21] DEBUG net.sf.hibernate.impl.BatcherImpl - preparing statement
201901 [http-8080-Processor21] DEBUG net.sf.hibernate.type.IntegerType - binding '52' to parameter: 1
201901 [http-8080-Processor21] DEBUG net.sf.hibernate.type.StringType - binding '123' to parameter: 2
201911 [http-8080-Processor21] DEBUG net.sf.hibernate.loader.Loader - processing result set
201911 [http-8080-Processor21] DEBUG net.sf.hibernate.loader.Loader - done processing result set (0 rows)
201911 [http-8080-Processor21] DEBUG net.sf.hibernate.impl.BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets
201911 [http-8080-Processor21] DEBUG net.sf.hibernate.impl.BatcherImpl - closing statement
201921 [http-8080-Processor21] DEBUG net.sf.hibernate.loader.Loader - total objects hydrated: 0
201921 [http-8080-Processor21] DEBUG net.sf.hibernate.impl.SessionImpl - initializing non-lazy collections
201921 [http-8080-Processor21] DEBUG net.sf.hibernate.hql.QueryTranslator - HQL: from com.dedalus.db.hibernate.Peca where id_empresa = ? and patrimonio = ? and action <> 'D'
201921 [http-8080-Processor21] DEBUG net.sf.hibernate.hql.QueryTranslator - SQL: select peca0_.id_peca as id_peca, peca0_.descricao as descricao, peca0_.id_Modelo as id_Modelo, peca0_.User_Id as User_Id, peca0_.id_empresa as id_empresa, peca0_.codigo_peca as codigo_p6_, peca0_.Action as Action, peca0_.Modified_Date as Modified8_ from Peca peca0_ where (id_empresa=? )and(patrimonio=? )and(action<>'D' )
201921 [http-8080-Processor21] DEBUG net.sf.hibernate.impl.BatcherImpl - about to open: 0 open PreparedStatements, 0 open ResultSets
201921 [http-8080-Processor21] DEBUG net.sf.hibernate.SQL - select peca0_.id_peca as id_peca, peca0_.descricao as descricao, peca0_.id_Modelo as id_Modelo, peca0_.User_Id as User_Id, peca0_.id_empresa as id_empresa, peca0_.codigo_peca as codigo_p6_, peca0_.Action as Action, peca0_.Modified_Date as Modified8_ from Peca peca0_ where (id_empresa=? )and(patrimonio=? )and(action<>'D' )
201921 [http-8080-Processor21] DEBUG net.sf.hibernate.impl.BatcherImpl - preparing statement
201941 [http-8080-Processor21] DEBUG net.sf.hibernate.type.IntegerType - binding '52' to parameter: 1
201941 [http-8080-Processor21] DEBUG net.sf.hibernate.type.StringType - binding '123' to parameter: 2
201951 [http-8080-Processor21] DEBUG net.sf.hibernate.util.JDBCExceptionReporter - SQL Exception
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid column name 'patrimonio'.
|