Hi,
I started the development of a new project and I intend to use Hibernate to ORM. After read the Bauer and King book and tried some tutorials I started my development. I am using Hibernate 3.0, Postgres 8.0, Eclipse 3.1 and the Hibernate Synchronizer with the snipes do hibernate 3.
After insert some data in different tables I tried to execute a simple query to recover an object from the database. I had the error: org.hibernate.QueryException: could not resolve property: codigodep of: sw3a.hibernate.Departamentos
Please could anyone help me? Thanks in advance.
celso
-------------------------
My configuration:
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping package="sw3a.hibernate">
<class name="Docentes" table="docentes">
<id name="Id" type="integer" column="iddocentes">
<generator class="native"/>
</id>
<property
name="Login"
column="login"
type="string"
not-null="true"
length="7"
/>
<property
name="Nome"
column="nome"
type="string"
not-null="true"
length="45"
/>
<many-to-one
name="DepartamentosIddep"
column="departamentos_iddep"
class="Departamentos"
not-null="true"
>
</many-to-one>
<set name="Turmas" inverse="true">
<key column="iddocentes"/>
<one-to-many class="Turmas"/>
</set>
</class>
</hibernate-mapping>
====================
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping package="sw3a.hibernate">
<class name="Departamentos" table="departamentos">
<id name="Id" type="integer" column="iddep">
<generator class="native"/>
</id>
<property
name="Codigodep"
column="codigodep"
type="string"
not-null="true"
length="3"
/>
<property
name="Nome"
column="nome"
type="string"
not-null="true"
length="30"
/>
<set name="Disciplinas" inverse="true">
<key column="iddep"/>
<one-to-many class="Disciplinas"/>
</set>
<set name="Docentes" inverse="true">
<key column="iddep"/>
<one-to-many class="Docentes"/>
</set>
</class>
</hibernate-mapping>
====================
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping package="sw3a.hibernate">
<class name="Turmas" table="turmas">
<id name="Id" type="java.lang.Long" column="idturma">
<generator class="increment"/>
</id>
<property
name="Codigoturma"
column="codigoturma"
type="string"
not-null="true"
length="4"
/>
<property
name="Tipoturma"
column="tipoturma"
type="boolean"
not-null="true"
length="1"
/>
<property
name="Aulasprevistas"
column="aulasprevistas"
type="java.lang.Long"
not-null="true"
length="4"
/>
<property
name="Diassemana"
column="diassemana"
type="string"
not-null="true"
length="5"
/>
<many-to-one
name="DocentesIddocentes"
column="docentes_iddocentes"
class="Docentes"
not-null="true"
>
</many-to-one>
<many-to-one
name="DisciplinasIddisciplina"
column="disciplinas_iddisciplina"
class="Disciplinas"
not-null="true"
>
</many-to-one>
<set name="Planilhanotasfaltas" inverse="true">
<key column="idturma"/>
<one-to-many class="Planilhanotasfaltas"/>
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Transaction tx = session.beginTransaction();
// Cree un Objet Departamentos
Departamentos dee = (Departamentos) session.createCriteria(Departamentos.class)
.add(Expression.eq("codigodep", "dee")).uniqueResult();
tx.commit();
Full stack trace of any exception that occurs:
04/08/2005 16:53:40 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.0.5
04/08/2005 16:53:40 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
04/08/2005 16:53:40 org.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
04/08/2005 16:53:40 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
04/08/2005 16:53:40 org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
04/08/2005 16:53:40 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
04/08/2005 16:53:40 org.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Alunos.hbm
04/08/2005 16:53:42 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: sw3a.hibernate.Alunos -> alunos
04/08/2005 16:53:42 org.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Departamentos.hbm
04/08/2005 16:53:44 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: sw3a.hibernate.Departamentos -> departamentos
04/08/2005 16:53:44 org.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Disciplinas.hbm
04/08/2005 16:53:46 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: sw3a.hibernate.Disciplinas -> disciplinas
04/08/2005 16:53:46 org.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Docentes.hbm
04/08/2005 16:53:52 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: sw3a.hibernate.Docentes -> docentes
04/08/2005 16:53:52 org.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Planilhanotasfaltas.hbm
04/08/2005 16:53:54 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: sw3a.hibernate.Planilhanotasfaltas -> planilhanotasfaltas
04/08/2005 16:53:54 org.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Turmas.hbm
04/08/2005 16:53:57 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: sw3a.hibernate.Turmas -> turmas
04/08/2005 16:53:57 org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
04/08/2005 16:53:57 org.hibernate.cfg.Configuration secondPassCompile
INFO: processing extends queue
04/08/2005 16:53:57 org.hibernate.cfg.Configuration secondPassCompile
INFO: processing collection mappings
04/08/2005 16:53:57 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: sw3a.hibernate.Alunos.Planilhanotasfaltas -> planilhanotasfaltas
04/08/2005 16:53:57 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: sw3a.hibernate.Departamentos.Disciplinas -> disciplinas
04/08/2005 16:53:57 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: sw3a.hibernate.Departamentos.Docentes -> docentes
04/08/2005 16:53:57 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: sw3a.hibernate.Disciplinas.Turmas -> turmas
04/08/2005 16:53:57 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: sw3a.hibernate.Docentes.Turmas -> turmas
04/08/2005 16:53:57 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: sw3a.hibernate.Turmas.Planilhanotasfaltas -> planilhanotasfaltas
04/08/2005 16:53:57 org.hibernate.cfg.Configuration secondPassCompile
INFO: processing association property references
04/08/2005 16:53:57 org.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
04/08/2005 16:53:57 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
04/08/2005 16:53:57 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
04/08/2005 16:53:57 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
04/08/2005 16:53:57 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.postgresql.Driver at URL: jdbc:postgresql:SW3A
04/08/2005 16:53:57 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=postgres, password=****}
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: PostgreSQL, version: 8.0.1
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.0devel JDBC3 with SSL (build 309)
04/08/2005 16:53:58 org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.PostgreSQLDialect
04/08/2005 16:53:58 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
04/08/2005 16:53:58 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: null
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
04/08/2005 16:53:58 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.EhCacheProvider
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
04/08/2005 16:53:58 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
04/08/2005 16:53:58 org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
04/08/2005 16:53:58 net.sf.ehcache.config.Configurator configure
WARNING: No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Arquivos%20de%20programas/Java/hibernate-3.0/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
04/08/2005 16:53:59 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
04/08/2005 16:53:59 org.hibernate.impl.SessionFactoryImpl checkNamedQueries
INFO: Checking 0 named queries
org.hibernate.QueryException: could not resolve property: codigodep of: sw3a.hibernate.Departamentos
at org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:37)
at org.hibernate.persister.entity.BasicEntityPersister.getSubclassPropertyTableNumber(BasicEntityPersister.java:1111)
at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:31)
at org.hibernate.persister.entity.BasicEntityPersister.toColumns(BasicEntityPersister.java:1086)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:403)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumnsUsingProjection(CriteriaQueryTranslator.java:369)
at org.hibernate.criterion.SimpleExpression.toSqlString(SimpleExpression.java:42)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:314)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:92)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1303)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:300)
at org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:433)
at sw3a.TesteInsertDocentes.main(TesteInsertDocentes.java:28)
Exception in thread "main"
Name and version of the database you are using: Postgres 8.0
Database SQL scripts:
DROP TABLE Alunos CASCADE;
DROP TABLE Disciplinas CASCADE;
DROP TABLE Turmas CASCADE;
DROP TABLE Departamentos CASCADE;
DROP TABLE Docentes CASCADE;
DROP TABLE PlanilhaNotasFaltas CASCADE;
DROP SEQUENCE hibernate_sequence;
CREATE SEQUENCE hibernate_sequence
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1;
ALTER TABLE hibernate_sequence OWNER TO postgres;
CREATE TABLE Alunos (
idaluno serial NOT NULL,
Matricula INT8 NOT NULL,
nomeAluno VARCHAR(50) NOT NULL,
abrAluno VARCHAR(20) NOT NULL,
loginAluno VARCHAR(8) NOT NULL,
tipoAluno INT2 NOT NULL,
CONSTRAINT "Alunos_PK" PRIMARY KEY (idAluno)
)
WITHOUT OIDS;
ALTER TABLE Alunos OWNER TO postgres;
CREATE TABLE Disciplinas (
idDisciplina serial NOT NULL,
Departamentos_idDep INT4 NOT NULL,
codigoDisciplina VARCHAR(7) NOT NULL,
Nome VARCHAR(30) NOT NULL,
cargaHoraria INT4 NOT NULL,
Serie INT2 NOT NULL
)
WITHOUT OIDS;
ALTER TABLE Disciplinas OWNER TO postgres;
ALTER TABLE Disciplinas ADD CONSTRAINT Disciplinas_PK PRIMARY KEY (idDisciplina);
CREATE TABLE Turmas (
idTurma serial NOT NULL,
Docentes_idDocentes INT4 NOT NULL,
Disciplinas_idDisciplina INT4 NOT NULL,
codigoTurma VARCHAR(4) NOT NULL,
tipoTurma BOOL NOT NULL,
aulasPrevistas INT4 NOT NULL,
diasSemana VARCHAR(5) NOT NULL
)
WITHOUT OIDS;
ALTER TABLE Turmas OWNER TO postgres;
ALTER TABLE Turmas ADD CONSTRAINT Turmas_PK PRIMARY KEY (idTurma);
CREATE TABLE Departamentos (
idDep serial NOT NULL,
CodigoDep VARCHAR(3) NOT NULL,
Nome VARCHAR(45) NOT NULL
)
WITHOUT OIDS;
ALTER TABLE Departamentos OWNER TO postgres;
ALTER TABLE Departamentos ADD CONSTRAINT Departamentos_PK PRIMARY KEY (idDep);
CREATE TABLE Docentes (
idDocentes serial NOT NULL,
Departamentos_idDep INT4 NOT NULL,
Login VARCHAR(7) NOT NULL,
Nome VARCHAR(45) NOT NULL
)
WITHOUT OIDS;
ALTER TABLE Docentes OWNER TO postgres;
ALTER TABLE Docentes ADD CONSTRAINT Docentes_PK PRIMARY KEY (idDocentes);
CREATE TABLE PlanilhaNotasFaltas (
idCelula serial NOT NULL,
Alunos_idAluno INT4 NOT NULL,
Turmas_idTurma INT4 NOT NULL,
refCelula VARCHAR(4) NOT NULL,
Ano INT4 NOT NULL,
tipoPublica BOOL NOT NULL,
tipoCelula INT2 NOT NULL,
conteudoCelula VARCHAR(30) NOT NULL
)
WITHOUT OIDS;
ALTER TABLE PlanilhaNotasFaltas OWNER TO postgres;
ALTER TABLE PlanilhaNotasFaltas ADD CONSTRAINT PlanilhaNotasFaltas_PK PRIMARY KEY (idCelula);
ALTER TABLE Turmas ADD CONSTRAINT FK_turIdDocentes FOREIGN KEY (Docentes_idDocentes) REFERENCES Docentes(idDocentes);
ALTER TABLE Docentes ADD CONSTRAINT FK_docIdDep FOREIGN KEY (Departamentos_idDep) REFERENCES Departamentos(idDep);
ALTER TABLE Disciplinas ADD CONSTRAINT FK_discIdDep FOREIGN KEY (Departamentos_idDep) REFERENCES Departamentos(idDep);
ALTER TABLE Turmas ADD CONSTRAINT FK_turIdDisc FOREIGN KEY (Disciplinas_idDisciplina) REFERENCES Disciplinas(idDisciplina);
ALTER TABLE PlanilhaNotasFaltas ADD CONSTRAINT FK_plaIdTurmas FOREIGN KEY (Turmas_idTurma) REFERENCES Turmas(idTurma);
ALTER TABLE PlanilhaNotasFaltas ADD CONSTRAINT FK_plaIdAluno FOREIGN KEY (Alunos_idAluno) REFERENCES Alunos(idAluno);
comment on column Alunos.idAluno is 'Chave Primária usada pelo Hibernate';
comment on column Alunos.nomeAluno is 'Nome completo do aluno';
comment on column Alunos.nomeAluno is 'Abreviação do nome do aluno utilizada na chamada';
comment on column Turmas.idTurma is 'Chave Primária usada pelo Hibernate';
comment on column Turmas.codigoTurma is 'Código da Turma. Ex.: 311, ESP.';
comment on column Turmas.tipoTurma is 'Tipo da Turma. Ex.: FALSE: Teoria / TRUE: Laboratório';
comment on column Turmas.aulasPrevistas is 'Número de aulas previstas em função dos dias letivos.';
comment on column Turmas.diasSemana is 'Dias da semana com aulas. 1-Seg / 2-Ter / 3-Qua / 4-Qui / 5 Sex. Podem ser representados mais de um dia.';
comment on column Departamentos.idDep is 'Chave Primária a ser utilizada pelo Hibernate.';
comment on column Departamentos.CodigoDep is 'Chave "Natural" da aplicação';
comment on column Departamentos.Nome is 'Nome do Departamento';
comment on column PlanilhaNotasFaltas.idCelula is 'Chave Primária para o Hibernate.';
comment on column PlanilhaNotasFaltas.refCelula is 'Identificador da célula da tabela. Ex,: A1, B3, C7.';
comment on column PlanilhaNotasFaltas.tipoPublica is 'FALSE indica que se trata de um nota e TRUE que se trata de uma falta';
comment on column PlanilhaNotasFaltas.tipoCelula is 'Número-1/fórmula-2/texto-3';
comment on column PlanilhaNotasFaltas.conteudoCelula is 'Conteúdo armazenado na célula';
-- End of generated script
|