-->
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: need help with the creation of hibernation query
PostPosted: Sat Nov 08, 2008 6:39 am 
Newbie

Joined: Sat Nov 08, 2008 6:14 am
Posts: 2
hi all,
I needed to convert a query to hibernate method.

The query i am using is
Select rollno,student_name,remarks from student where rollno=?
and remarks like '%passed ? and failed ?'

i am having a column called remarks which will have string value but last elements will be passed 4 and failed 2.

so how to convert to this to a hibernate query


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 08, 2008 8:44 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
I don't know how much experience do you have .Any way for this you need to have object modeling and map those object with respective table by hibernate and then you could fetch object by either hql or criteria.

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 08, 2008 8:53 am 
Newbie

Joined: Sat Nov 08, 2008 6:14 am
Posts: 2
I have not much experience with hibernate queries. But with some searches i have found to make a bean class Student class. i want help to create Student.hbm.xml file for the above query.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 08, 2008 10:19 am 
Newbie

Joined: Fri Sep 26, 2008 4:45 am
Posts: 17
for the query you can do

Code:
Criteria criteria = session.createCriteria(Student.class);
criteria.add(Expression.like("remarks", remark);
criteria.add(Expression.eq("rollino", rollino);
return criteria.list()


don't create a hbm file for the mapping you have annotations to do that

Code:
@Entity

public class Student {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    private long rollino;


    @Column(name = "remarks", length = 20, nullable = true)
    private String remarks;

    ...getter and setter
}


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.