-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Problem with a simple query
PostPosted: Thu Aug 04, 2005 6:41 pm 
Newbie

Joined: Thu Aug 04, 2005 5:34 pm
Posts: 5
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 6:49 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
You defined...
<property
name="Codigodep"
column="codigodep"
type="string"
not-null="true"
length="3"
/>


but you are requesting:

Departamentos dee = (Departamentos) session.createCriteria(Departamentos.class)
.add(Expression.eq("codigodep", "dee")).uniqueResult();


Try it again after you have renamed the property.

Best regards
Sven


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 7:12 pm 
Newbie

Joined: Thu Aug 04, 2005 5:34 pm
Posts: 5
Hi,

Thank you. I changed codigodep to Codigodep but now I have another error...

INFO: Checking 0 named queries
Hibernate: select this_.iddep as iddep0_, this_.codigodep as codigodep1_0_, this_.nome as nome1_0_ from departamentos this_ where this_.codigodep=?
Hibernate: select docentes0_.iddep as iddep1_, docentes0_.iddocentes as iddocentes1_, docentes0_.iddocentes as iddocentes0_, docentes0_.login as login3_0_, docentes0_.nome as nome3_0_, docentes0_.departamentos_iddep as departam4_3_0_ from docentes docentes0_ where docentes0_.iddep=?
04/08/2005 20:05:18 org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 0, SQLState: 42703
04/08/2005 20:05:18 org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ERROR: column docentes0_.iddep does not exist
org.hibernate.exception.SQLGrammarException: could not initialize a collection: [sw3a.hibernate.Departamentos.Docentes#3]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1441)
at org.hibernate.loader.collection.OneToManyLoader.initialize(OneToManyLoader.java:111)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:488)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1430)
at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:280)
at org.hibernate.engine.PersistenceContext.initializeNonLazyCollections(PersistenceContext.java:796)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:111)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1322)
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)
Caused by: java.sql.SQLException: ERROR: column docentes0_.iddep does not exist
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1365)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1160)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:172)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:387)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:328)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:238)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:120)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1272)
at org.hibernate.loader.Loader.doQuery(Loader.java:391)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1434)
... 14 more
Exception in thread "main"

I would like to create an object "Departamentos" to insert in "Docentes" that I would like to create. I am wrong? There is another way to insert an object "Docente". In my table Docentes I have a foreign key from the Departamentos table. It is mapped like:

<many-to-one
name="DepartamentosIddep"
column="departamentos_iddep"
class="Departamentos"
not-null="true"
>
</many-to-one>

in Docentes.hbm.

Any ideas? Thanks,

celso


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 7:27 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
You column names of your bidirectional associations (one-to-many + many-to-one) have to match.

Your error occurs because Hibernate (resp. your database afterwards) is looking for a table column "iddep" in your table "Docentes". But there is only a column "departamentos_iddep".

Class: Docentes
<many-to-one
name="DepartamentosIddep"
column="departamentos_iddep"
class="Departamentos"
not-null="true"
>
</many-to-one>


Class: Departamentos
<set name="Docentes" inverse="true">
<key column="iddep"/>
<one-to-many class="Docentes"/>
</set>

Best regards
Sven


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 9:26 am 
Newbie

Joined: Thu Aug 04, 2005 5:34 pm
Posts: 5
Hi Sven,

Thank you very much! Now I can insert a docente object.

celso


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.