-->
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: Retrieve Data Error in Hibernate3
PostPosted: Mon May 22, 2006 5:48 pm 
Newbie

Joined: Mon May 22, 2006 5:36 pm
Posts: 1
Hi,

I am trying to retrieve date from one persistent class which has primary key as an Integer datatype, as follows annotation.

@Id(generate = GeneratorType.AUTO)
@Column(name = "seq_no")
public Integer getSeqNo() {
return SeqNo;
}


When I try to retrieve the data using the following code, I always get the following error.

Retrieve Code:

Criteria criteria = session.createCriteria(RateLockData.class)
.add(Expression.eq("seqNo", seqNo));

RateLockData ratelock = (RateLockData) criteria.uniqueResult();

Error Message:

java.lang.ClassCastException: java.lang.Integer
at org.hibernate.type.StringType.toString(StringType.java:42)
at org.hibernate.type.NullableType.toLoggableString(NullableType.java:122)

I use Hibernate3. Does anyone has solutions for this ?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 22, 2006 7:22 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
If I recall correctly then Hibernate has bug here. You need to specify type of ID explicitly. Hibernate cannot infer it via reflection when annotations are used

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 22, 2006 9:51 pm 
Regular
Regular

Joined: Thu Sep 22, 2005 1:53 pm
Posts: 88
Location: Rio de Janeiro
I used something like this:

Code:
   @Id
   @GeneratedValue(strategy=GenerationType.AUTO)
   @Column(name="id_solicitacao", nullable=false)
   public Integer getId() {
      return id;
   }


And that worked fine with this criteria :

Code:
  session.createCriteria(......)   
      .add(Restrictions.idEq(1))
      .uniqueResult();


I am using the latest build of hibernate annotations and hibernate


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 22, 2006 10:14 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Try adding this:
@Id
@Type(type="java.lang.Integer")
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="id_solicitacao", nullable=false)
public Integer getId() {
return id;
}

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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.