-->
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.  [ 3 posts ] 
Author Message
 Post subject: NullPointerException when I Try to retrieve information
PostPosted: Fri Feb 23, 2007 2:42 pm 
Newbie

Joined: Fri Feb 23, 2007 2:16 pm
Posts: 2
This is the problem. I have two entities: Profile and User.
1 user has many profiles
But 1 user also has an "active profile". An active profile is the profile this user is currently using.

Table USER:

USER_ID: VARCHAR(10)
NAME: VARCHAR(20)
EMAIL: VARCHAR(20)
SERIAL_NUMBER:VARCHAR(20)
PROFILE_ID: INTEGER (this is the foreign key that references the active profile)

Table PROFILE:

PROFILE_ID: INTEGER
NAME: VARCHAR_20
USER_ID: VARCHAR(10) (This is the Foreign Key that indicutes whose profile is this).

My Classes:
public class User {
private String userID;

private String name;

private String email;

private String serialNumber;

private List profiles;

private Profile activeProfile;
//getters, setters, etc...
}

public class Profile {

private int profileID;

private String name;

//getters, setters, etc...
}

The problem is: After I mapped the activeProfile in the user.hbm.xml I get NullPointerExceptions when I try to retrieve Users that actually have an active profile setted. This error does not occur when I try to retrieve users that do not have active profiles set (Their PROFILE_ID column is null).

Can anyone here please help me?

Here are my .hbm.xml files:

<hibernate-mapping>

<class name=User"
table="USER" >

<id name="userID" column="USER_ID"/>

<property name="name" column="NAME" />
<property name="email" column="EMAIL" />
<property name="serialNumber" column="SERIAL_NUMBER" />

<!--<many-to-one name="activeProfile" column="ACTIVE_PROFILE"
class="Profile"
cascade="all"/>-->

<many-to-one name="activeProfile"
class="com.ibm.extremeblue.callhandling.entities.Profile"
column="PROFILE_ID" insert="false" update="true"/>

<bag name="profiles" table="PROFILE" cascade="all">
<key column="USER_ID" />
<one-to-many class="Profile"/>
</bag>

</class>

</hibernate-mapping>

<hibernate-mapping>

<class name="Profile" table="PROFILE">

<id name="profileID" column="PROFILE_ID">
<generator class="identity" />
</id>

<property name="name" column="NAME" />

</class>

</hibernate-mapping>

The exception stack trace is:

Exception in thread "main" java.lang.NullPointerException
at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3121)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:232)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:173)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:830)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
at org.hibernate.type.EntityType.resolve(EntityType.java:303)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1785)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:47)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:41)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2730)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:177)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:799)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:792)
at com.ibm.extremeblue.callhandling.persistence.UserDAO.loadUser(UserDAO.java:19)
at com.ibm.extremeblue.callhandling.persistence.UserDAO.main(UserDAO.java:41)

Hibernate version:
3.2

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 24, 2007 6:30 am 
Beginner
Beginner

Joined: Thu Feb 08, 2007 11:11 am
Posts: 24
Location: India
you did a mistake!!!!!!!!!!

Ur user table has a foreign key to profile table, simultaneously
ur profile table has a foreign key to user table.

[color=darkred][u][i][b]HOW COULD IT BE?[/b][/i][/u][/color]

Make profiles independant of user.
An user may have multiple profile, store them in Set for the java class
with one active_profile number.

That's it.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 24, 2007 8:16 pm 
Newbie

Joined: Fri Feb 23, 2007 2:16 pm
Posts: 2
I didn't understand your solution.
The foreign key the user has to profile indicates which profile is that user's active profile.
How should the tables be then?

Thanks for your help!


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