I am using Spring mvc and hibernate.I want to put WHERE condition and get specific result then i want to convert in to LIst ,I did it like that..but give ERRORS..
Please simple tell if some one want to convert any table to list .do we shud change in MODEL
This is MODEL**
package pearson.dashboard.model;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
@Entity
public class Meetings {
@Id
@Column
@GeneratedValue(strategy=GenerationType.AUTO)
private int meetingID;
@Column
private Date sheduleTime;
@Column
private String meetingHeading;
@Column
private String comment;
@Column
private String roomName;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "meetingTypeID")
private MeetingTypes meetingTypes;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "releaseID")
private Releases releases;
public Releases getReleases() {
return releases;
}
public void setReleases(Releases releases) {
this.releases = releases;
}
public MeetingTypes getMeetingTypes() {
return meetingTypes;
}
public void setMeetingTypes(MeetingTypes meetingTypes) {
this.meetingTypes = meetingTypes;
}
public Meetings() {
// TODO Auto-generated constructor stub
}
public Meetings(int meetingID, Date sheduleTime, String meetingHeading,
String comment, String roomName) {
super();
this.meetingID = meetingID;
this.sheduleTime = sheduleTime;
this.meetingHeading = meetingHeading;
this.comment = comment;
this.roomName = roomName;
}
public int getMeetingID() {
return meetingID;
}
public void setMeetingID(int meetingID) {
this.meetingID = meetingID;
}
public Date getSheduleTime() {
return sheduleTime;
}
public void setSheduleTime(Date sheduleTime) {
this.sheduleTime = sheduleTime;
}
public String getMeetingHeading() {
return meetingHeading;
}
public void setMeetingHeading(String meetingHeading) {
this.meetingHeading = meetingHeading;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public String getRoomName() {
return roomName;
}
public void setRoomName(String roomName) {
this.roomName = roomName;
}
}
Dao**
@Transactional
@Repository
public class MeetingTypeDaoImpl implements MeetingTypeDao {
@Autowired
private SessionFactory sessionFactory;
public List getAllMeetingTypes(int releaseID) {
// TODO Auto-generated method stub
Query query = sessionFactory.getCurrentSession().createQuery("from Meetings where releaseID = :releaseID");
query.setParameter("releaseID", releaseID);
List list = query.list();
if(list!=null && list.size()>0){
return (List) list.get(0);//when i remove castin it give error that why i casted
}else{
return null;
}
}
}
Part of Erro***
Dec 04, 2013 2:19:53 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [appServlet] in context with path [/controller] threw exception [Request processing failed; nested exception is java.lang.ClassCastException: pearson.dashboard.model.Meetings cannot be cast to java.util.List] with root cause
java.lang.ClassCastException: pearson.dashboard.model.Meetings cannot be cast to java.util.List
at pearson.dashboard.dao.impl.MeetingTypeDaoImpl.getAllMeetingTypes(MeetingTypeDaoImpl.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)