-->
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: problem between hiberante's createQuery() and get()
PostPosted: Fri Feb 03, 2012 12:09 am 
Newbie

Joined: Thu Feb 02, 2012 11:28 pm
Posts: 13
Location: shenzhen china
I got a problem about hibernate query;

blow is the code:

Session session = this.getSession();
TBlogArticle article = (TBlogArticle)session.createQuery( "from TBlogArticle t where t.blogId=?").setLong(0, article.getBlogId()).uniqueResult();

I can get the "article"

If the code is :

TBlogArticle articleobj = (TBlogArticle)baseDao.get(TBlogArticle.class, article.getBlogId());
There will be a nullpointer. "articleobj" is null(table "TBlogArticle " has a primary key);

why ?

thanks very much!

中文
使用createQuery方法能查出对象
Session session = this.getSession();
TBlogArticle articleobj = (TBlogArticle)session.createQuery( "from TBlogArticle t where t.blogId=?").setLong(0, article.getBlogId()).uniqueResult();



为什么使用hibernate的get()或者load()方法就不能查询出对象,且出现空指针异常
TBlogArticle articleobj = (TBlogArticle)baseDao.get(TBlogArticle.class, article.getBlogId());求教大师,谢谢!


Top
 Profile  
 
 Post subject: Re: problem between hiberante's createQuery() and get()
PostPosted: Fri Feb 03, 2012 7:36 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
How should any person help you, if you don't report here the code of your baseDao class
and if you don't report the NullPointerException with stacktrace.
Please also provide the line-numbers of your java-code so that from the stacktrace is visible which exactly is the line which throws NullPointerException


Top
 Profile  
 
 Post subject: Re: problem between hiberante's createQuery() and get()
PostPosted: Sun Feb 05, 2012 11:10 pm 
Newbie

Joined: Thu Feb 02, 2012 11:28 pm
Posts: 13
Location: shenzhen china
pb00067 wrote:
How should any person help you, if you don't report here the code of your baseDao class
and if you don't report the NullPointerException with stacktrace.
Please also provide the line-numbers of your java-code so that from the stacktrace is visible which exactly is the line which throws NullPointerException


Thanks for your reply!

I have found why through checking code.
My mind is cluttered with thoughts in several days.

My english is not very well ,I hope you can understand what i said.

I am studying hard!


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.