-->
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.  [ 15 posts ] 
Author Message
 Post subject: null pointer exception in hibernate code generation
PostPosted: Thu Feb 16, 2006 3:00 pm 
Beginner
Beginner

Joined: Sun Jan 22, 2006 8:47 pm
Posts: 31
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.0


Name and version of the database you are using:mssqlserver8

Hi ,
Iam a newbie trying to learn hibernate..
I am using eclipse ide 3.1 (wtp)
with eclipse jboss plugin :1.5.0
jdk 1.4.2_10

Hibernate tools were installed in eclipse as a part of jboss-eclipse ide..
I started a sample Java project and followed the eclipse help tutorial in using hibernate tools ..

I created

1)hibernate.cfg.xml using the wizzard.
2)hibernate console configuration
3)reveng.xml file
4)Hibernate code Generation..(In this I selected the hibernate.reveng.xml defined in step 3)

when i run the Hibernate code Generation ,Iam having Null Pointer Exception.

I dont have access to view the DB schema..so even though the tables have primary key,Iam getting warnings like the tables doesnt have primary key.Can this be a problem?

In hibernate-reveng.xml i have explictly specified the priamry key in Tables&Columns section.
I think iam doing sth wrong..Can any one pls help me..
Thnx.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 17, 2006 3:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
where is the nullpointer exception ?

is there a stacktrace in the errror log view ?

...have you updated to the beta4 of hibernate tools ? (jbosside 1.5.0 comes with beta3)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 17, 2006 1:03 pm 
Beginner
Beginner

Joined: Sun Jan 22, 2006 8:47 pm
Posts: 31
Hi Max,

I dont know the cause of NullPointerException,but once i restarted the eclipse i was able to run the query.Shall i update to beat4 of hibernate-tools?

I need a good tutorial to study to learn using the hibernate tools from eclipse..I went thru this

http://www.hibernate.org/hib_docs/tools ... gle/#setup

I couldn't learn from this tutorial how to specify associations (set,map ..) using these tools..If u can u pls provide the link to learn these things it will be grt.

Thnx,


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 17, 2006 1:59 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
why should you not update to beta4 ? :)

there are no support for specifying set,map etc. for foreignkeys yet.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 17, 2006 2:47 pm 
Beginner
Beginner

Joined: Sun Jan 22, 2006 8:47 pm
Posts: 31
Hi Max,

Thnx for the reply..
So if i want to define associations for a class ,do i need to define them manually in my mapping files or there are any kind of tools that i need to download?

Iam a newbie and dont have much idea of what kind of tools are available for Hibernate .Pls suggest

Thnx


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 17, 2006 4:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
define them in the mappings manually is the way to go now.

(the cvs version of middlegen has some deeper support here if you want to try that out)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 21, 2006 2:53 pm 
Beginner
Beginner

Joined: Sun Jan 22, 2006 8:47 pm
Posts: 31
Hi Max,

Sorry iam still trying to get this done..After running Hibernate Code generation in which I used my hibernate-reveng.xml ,I have got all the mapping files and POJO's .ok...

Now in order to add associations like "set" I manually edited the xml mapping files by adding <set> tag and added the relevant code to the POJO class.Now when I try to access the set as a property of this class in hibernate query ,Iam getting

could not resolve property exception..

After manually changing the mapping files and POJO's is it sufficient to just save them and run the hql..My doubt is the v shuldn't run the code generation again right..i cant undersatnd when i have added the set as a property why is iam having exception...pls advice..do we need to do any changes in hibernate-reveng.xml ?

Thnx,


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 21, 2006 6:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
so your pojo's does not contain the apropriate property.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 12:20 pm 
Beginner
Beginner

Joined: Sun Jan 22, 2006 8:47 pm
Posts: 31
Hi Max,

I have included the changes i have made to the mapping file after running Hibernate code generation..

<hibernate-mapping>
<class name="Appt" table="appt" schema="dbo" catalog="test">

<set name="resUnit" table="resunit" >
<key column="resunit_id"/>
<one-to-many class="Resunit" />
</set>

</class>
</hibernate-mapping>
____________________
Appt.java :


public class Appt implements java.io.Serializable {

private Set resUnit=new HashSet();

public Set getResUnit() {
return this.resUnit;
}

public void setResUnit(Set resUnit1) {
this.resUnit = resUnit1;
}

}

____________________________________

Hql Query:

select resunit.resunitId from Appt appt inner join appt.resUnit resunit

________________________________________
Exception :
org.hibernate.QueryException: could not resolve property: resUnit of: Appt [select resunit.resunitId from Appt appt inner join appt.resUnit resunit]

_____________________________________________

Event though I have provided the set and get in POJO for this set association ,Iam not able to figure out why it is not able to resolve property "resUnit"?
I can see the set with name "resUnit " in the " outline " window pane as a property of Appt..


i just saved the mapping file and tried to execute the hql in HQL scratchPad.Do I need to do anyother way?Pls help!

Tnx a lot for your help..


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 12:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
and you are sure the console configuration is actually loading that mapping file and compiled classes ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 12:34 pm 
Beginner
Beginner

Joined: Sun Jan 22, 2006 8:47 pm
Posts: 31
How can I make sure about that?
Thnx


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 12:39 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
if the mappings and the classpath in the console configuraiton is correct then close the sessionfactory and open it again to make it reload.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 1:06 pm 
Beginner
Beginner

Joined: Sun Jan 22, 2006 8:47 pm
Posts: 31
I think the problem is some thing related to what you have pointed out..Its not picking up the updated mapping files..

if the mappings and the classpath in the console configuraiton is correct then close the sessionfactory and open it again to make it reload.

Sorry ,I didnt get it..What are needed to be in the classpath of ConsoleConfiguration ?Iam just refreshing CondoleConfig,but its not picking up the changes made to these mapping files..How do i make sure tht its picking up the changes..Pls advice.
Thnx for ur help.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 1:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
dont just refresh. close and open the sessionfactory.

(i should remove the refresh button actually)

and read the docs for what needs to be in the console configuration classpath....it has been stated many times (in short the classes needed to load your POJO's, including the pojo's itself and dependent libs but NOT hibernate core libraries)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 1:58 pm 
Beginner
Beginner

Joined: Sun Jan 22, 2006 8:47 pm
Posts: 31
Thnx Max,its working now...closing and opening the session factory helped .
Thnx a lot 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.  [ 15 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.