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: getting object values from a database
PostPosted: Fri May 08, 2009 9:38 am 
Newbie

Joined: Wed May 06, 2009 10:00 am
Posts: 6
Hello - I need an id from a table as a object type - I see in a lot of tutorials that you can cast the Object query, but I just get that an integer cannot be cas to TOperands:

public TOperands getTOperands(){

TOperands newOp= new TOperands();
Object query=null;

try {

org.hibernate.Transaction tx = session.beginTransaction();

Query q=session.createQuery("select id from TOperands where op=':=' ");
query=q.uniqueResult();


tx.commit();
session.close();
} catch (Exception e) {
e.printStackTrace();
}

System.out.println(query);
TOperands op=(TOperands) query;
return op;
}


Do anyone know why??, I really dont understand how I gonna get the id as a TOperands type in another way.


Top
 Profile  
 
 Post subject: Re: getting object values from a database
PostPosted: Fri May 08, 2009 10:11 am 
Beginner
Beginner

Joined: Tue Mar 10, 2009 11:50 pm
Posts: 23
What does your TOperands class contain. Does it have any id properties within it ?

_________________
Cheers,

Vinod
We act as though comfort and luxury were the chief requirements of life, when all that we need to make us happy is something to be enthusiastic about


Top
 Profile  
 
 Post subject: Re: getting object values from a database
PostPosted: Fri May 08, 2009 10:30 am 
Newbie

Joined: Wed May 06, 2009 10:00 am
Posts: 6
this is the TOperand class:

package wlcresepsjon;
// Generated 08.mai.2009 12:23:28 by Hibernate Tools 3.2.1.GA


import java.util.HashSet;
import java.util.Set;

/**
* TOperands generated by hbm2java
*/
public class TOperands implements java.io.Serializable {


private int id;
private String op;
private String comment;
private Set<TRadreply> TRadreplies = new HashSet<TRadreply>(0);

public TOperands() {
}


public TOperands(int id, String op) {
this.id = id;
this.op = op;
}
public TOperands(int id, String op, String comment, Set<TRadreply> TRadreplies) {
this.id = id;
this.op = op;
this.comment = comment;
this.TRadreplies = TRadreplies;
}



public int getId() {
return this.id;
}

public void setId(int id) {
this.id = id;
}
public String getOp() {
return this.op;
}

public void setOp(String op) {
this.op = op;
}
public String getComment() {
return this.comment;
}

public void setComment(String comment) {
this.comment = comment;
}
public Set<TRadreply> getTRadreplies() {
return this.TRadreplies;
}

public void setTRadreplies(Set<TRadreply> TRadreplies) {
this.TRadreplies = TRadreplies;
}




}

thanks for all 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.