-->
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.  [ 4 posts ] 
Author Message
 Post subject: Null pointer on a many to one relationship
PostPosted: Wed Sep 13, 2006 10:42 pm 
Newbie

Joined: Fri Aug 05, 2005 3:42 pm
Posts: 12
Hi i´m using Hibernate 2.0 and i´m getting a NullPointerException

It happens when i call a method find("from Usuario")

Here is the Hibernate Query generated

**********************************************
Hibernate: select usuario0_.id_usuario as id_usuario, usuario0_.nm_usuario as nm_usuario, usuario0_.ds_login as ds_login, usuario0_.cd_senha as cd_senha, usuario0_.ds_email as ds_email, usuario0_.fl_ativo as fl_ativo, usuario0_.id_tipo_usuario as id_tipo_7_ from usuario usuario0_
Hibernate: select tipousuari0_.id_tipo_usuario as id_tipo_1_0_, tipousuari0_.ds_tipo_usuario as ds_tipo_2_0_ from tipo_usuario tipousuari0_ where tipousuari0_.id_tipo_usuario=?
java.lang.NullPointerException

**********************************************

Here is the hibernate map

**********************************************

<!-- Associations On Usuario-->

<!-- bi-directional many-to-one association to TipoUsuario -->
<many-to-one
name="tipoUsuario"
class="br.com.efat2.frw.beans.TipoUsuario"
not-null="true"
>
<column name="id_tipo_usuario" />
</many-to-one>

<!-- Associations On TipoUsuario-->
<one-to-many
class="br.com.efat2.frw.beans.Usuario"
/>

**********************************************

-- Table: usuario

-- DROP TABLE usuario;

CREATE TABLE usuario
(
id_usuario int4 NOT NULL DEFAULT nextval('usuario_id_usuario_seq'::regclass),
id_tipo_usuario int4 NOT NULL,
nm_usuario char(200),
ds_login char(50),
cd_senha char(150),
ds_email char(200),
fl_ativo char(1),
CONSTRAINT usuario_pkey PRIMARY KEY (id_usuario),
CONSTRAINT usuario_id_tipo_usuario_fkey FOREIGN KEY (id_tipo_usuario)
REFERENCES tipo_usuario (id_tipo_usuario) MATCH SIMPLE
ON UPDATE RESTRICT ON DELETE RESTRICT
)
WITHOUT OIDS;
ALTER TABLE usuario OWNER TO postgres;


-- Table: tipo_usuario

-- DROP TABLE tipo_usuario;

CREATE TABLE tipo_usuario
(
id_tipo_usuario int4 NOT NULL DEFAULT nextval('tipo_usuario_id_tipo_usuario_seq'::regclass),
ds_tipo_usuario char(100),
CONSTRAINT tipo_usuario_pkey PRIMARY KEY (id_tipo_usuario)
)
WITHOUT OIDS;
ALTER TABLE tipo_usuario OWNER TO postgres;





Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 14, 2006 2:35 am 
Newbie

Joined: Thu Apr 27, 2006 9:56 am
Posts: 14
Location: Hyderabad
I think u r going wrong in creating mapping for ur calss

Error while writing mapping for many-to-one relation

Here is sample mapping file. Hope it may be useful for u.

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="mypack">
<class table="CLIENTS" name="Clients">
<id type="java.math.BigDecimal" column="CLIENT_ID" access="property" name="clientId">
<generator class="sequence">
<param name="sequence">CLIENT_ID_SQ</param>
</generator>
</id>
<many-to-one not-null="true" access="property" name="Config">
<column name="CONFIG_ID"/>
</many-to-one>

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject: Maps
PostPosted: Thu Sep 14, 2006 12:51 pm 
Newbie

Joined: Fri Aug 05, 2005 3:42 pm
Posts: 12
THis is only a part of the map....I generated with Middle Gen.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 14, 2006 11:52 pm 
Newbie

Joined: Fri Aug 05, 2005 3:42 pm
Posts: 12
This is the mapping for sequence?

<hibernate-mapping package="br.com.efat2.frw.beans">
<class table="Usuario" name="Usuario">
<id type="java.lang.Integer" column="CLIENT_ID" access="property" name="ID_USUARIO">
<generator class="sequence">
<param name="sequence">usuario_seq_id_usuario</param>
</generator>
</id>
<many-to-one not-null="true" access="property" name="Config">
<column name="CONFIG_ID"/>
</many-to-one>

</class>
</hibernate-mapping>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.