psb
#1
Estou tendo problemas com o hibernate.
Estou usando o sgbd postgres, estou tendo problema na hora de inicializar o arquivo de configuracao do hibernate.
Fiz um teste bem simples! Estou usando aquele plugin Hibernate Synchronizer …
No mapeamento das minhas classes, eu tenho foreign key´s.
Veja o erro que aparece no output.
Hibernate ...
20/08/2004 10:18:51 net.sf.hibernate.cfg.Environment <clinit>
INFO: Hibernate 2.1.6
20/08/2004 10:18:51 net.sf.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
20/08/2004 10:18:51 net.sf.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
20/08/2004 10:18:51 net.sf.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
20/08/2004 10:18:51 net.sf.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
20/08/2004 10:18:51 net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: org/pablo/Cliente.hbm.xml
20/08/2004 10:18:52 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: org.pablo.Cliente -> cliente
20/08/2004 10:18:52 net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: org/pablo/Endereco.hbm.xml
20/08/2004 10:18:52 net.sf.hibernate.util.XMLHelper$ErrorLogger error
SEVERE: Error parsing XML: XML InputStream(21) The content of element type "class" must match "(meta*,(cache|jcs-cache)?,(id|composite-id),discriminator?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|any|map|set|list|bag|idbag|array|primitive-array)*,(subclass*|joined-subclass*))".
HibernateException = Error reading resource: org/pablo/Endereco.hbm.xml
Alguem sabe, algo do genero, o erro pode ser no mapeamento do xml?

Seu mapeamento parece estar errado…
Coloque ele aqui para ver se podemos ajudar!
Fallow
aborges
#3
Ele nao esta achando seu hibernate.properties tb!
INFO: hibernate.properties not found
[quote=“aborges”]Ele nao esta achando seu hibernate.properties tb!
INFO: hibernate.properties not found
Certo, mas lembre-se que ele não precisa possuir um hibernate.properties. Ele pode estar configurando tudo no hibernate.cfg.xml.
Esse, aparentemente foi encontrado, veja:
INFO: configuring from resource: /hibernate.cfg.xml
Fallow
aborges
#5
Ops! Vc esta certo :oops: :oops: :oops:
psb
#6
Estrutura das tabelas no postgres. Vejam
hibernate=# d cliente
Table "public.cliente"
Column | Type | Modifiers
-------------+-------------------+---------------------------------------------------------
id | integer | not null default nextval('public.cliente_id_seq'::text)
nome | character varying | not null
idade | integer | not null
id_endereco | integer | not null
Indexes:
"cliente_pkey" primary key, btree (id)
Foreign-key constraints:
"fk_id_endereco" FOREIGN KEY (id_endereco) REFERENCES endereco(id)
hibernate=# d endereco
Table "public.endereco"
Column | Type | Modifiers
----------+-------------------+----------------------------------------------------------
id | integer | not null default nextval('public.endereco_id_seq'::text)
endereco | character varying | not null
Indexes:
"endereco_id_key" unique, btree (id)
hibernate=#
Mapeamento da tabela, Cliente, gerado pelo Hibernate Synchronizer:
<?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="org.pablo">
<class name="Cliente" table="cliente">
<id
column="id"
name="Id"
type="java.lang.Long"
>
<generator class="vm" />
</id>
<property
column="nome"
name="Nome"
not-null="true"
type="string"
/>
<property
column="idade"
length="4"
name="Idade"
not-null="true"
type="java.lang.Long"
/>
<many-to-one
class="Endereco"
name="IdEndereco"
not-null="true"
>
<column name="id_endereco" />
</many-to-one>
</class>
</hibernate-mapping>
Mapeamento da tabela endereco …
<?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="org.pablo">
<class name="Endereco" table="endereco">
<property
column="endereco"
name="Endereco"
not-null="true"
type="string"
/>
<property
column="id"
length="4"
name="Id"
not-null="true"
type="java.lang.Long"
/>
</class>
</hibernate-mapping>
O erro que estou tendo e aquele, que postei logo ali acima?
Alguem …
To achando q isso e problema da cardinalidade.
Ou seja.
Um cliente pode ter varios enderecos?
Ou um endereco pode ter n clientes?

O problema é que seu Endereco não possui chave…
Veja esse trecho retirado da documentação do Hibernate:
Fallow