-->
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: Strange problem: Cannot get ID
PostPosted: Tue Mar 08, 2005 4:06 pm 
Newbie

Joined: Tue Mar 08, 2005 2:26 pm
Posts: 1
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:2.1


<hibernate-mapping>
<class name="Conference.Paper" table="paper">
<id name="id" column="id" type="java.lang.Integer" unsaved-value="any">
<generator class="assigned"/>
</id>
<property name="title" column="title" type="string" not-null="true"/>
<property name="filetype" column="filetype" type="string" not-null="false"/>
<property name="abStract" column="abStract" type="string" not-null="false"/>
<property name="userid" column="userid" type="java.lang.Integer" not-null="true"/>

</class>
</hibernate-mapping>



StringBuffer s=new StringBuffer("select c from Paper as c where c.userid='");
s.append(userid);
s.append("'");
beginTransaction();
Query query=session.createQuery(s.toString());
Iterator it=query.iterate();
while(it!=null && it.hasNext())
{
Paper paper=(Paper)it.next();
System.out.println("Paperid="+paper.getId());
}

return it;



***********************************
the problem is weird: I can get all properties except id. It just looks like the getId() method always returns 0.Why??
Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 08, 2005 7:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Well, you are using generator=assigned, do you assign the ids?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 08, 2005 7:35 pm 
Beginner
Beginner

Joined: Mon Nov 29, 2004 5:34 pm
Posts: 35
Do you get any results in your Iterator it, what is the size of it.

But if you want to check the quick alternative to get the same thing you are doing, you can try this :-

List results = session.createCriteria(Paper.class)
.add( Expression.eq("userid", Obj.getUserID())).list();

And then iterate as you were doing, hope you will get the required results.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 08, 2005 7:37 pm 
Beginner
Beginner

Joined: Mon Nov 29, 2004 5:34 pm
Posts: 35
Forget to mention, best way to debug is turn on your sql statements in main hibernate mapping file, so you get the exact SQL generated and get to the error immediately.

srigold


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.