Here i have two tables which are not mapped to each other....when i write a query to fetch records from two tables it is displaying following output as shown in console. but how to print the list inside jsp page according to the date of two tables in descending order????
Error:
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.bdisys.promorphics.domain.Blog
at com.bdisys.promorphics.dao.impl.BlogDaoImpl.getTopBlogsQuesByDate(BlogDaoImpl.java:147)
at org.apache.jsp.Mydetails_jsp._jspService(Mydetails_jsp.java:937)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:381)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Unknown Source)
blogs are====[[Ljava.lang.Object;@55de08, [Ljava.lang.Object;@163f5f5, [Ljava.lang.Object;@1a8c542, [Ljava.lang.Object;@12e99f0, [Ljava.lang.Object;@7c6b8e, [Ljava.lang.Object;@794e73, [Ljava.lang.Object;@d6e9f, [Ljava.lang.Object;@1d9b9fd, [Ljava.lang.Object;@1419a32, [Ljava.lang.Object;@1f280a7, [Ljava.lang.Object;@1dc8c55, [Ljava.lang.Object;@81475b, [Ljava.lang.Object;@173e739, [Ljava.lang.Object;@51550e, [Ljava.lang.Object;@1a73e9c, [Ljava.lang.Object;@ffa7e7, [Ljava.lang.Object;@68531b, [Ljava.lang.Object;@1282f92, [Ljava.lang.Object;@14b261e, [Ljava.lang.Object;@b3a43d]
This is my Daoimpl method,where i am writing a query:i tried it in many ways but it is showing errors b!!can any one tell the exact solution for this???
@SuppressWarnings("unchecked")
public List<Blog> getTopBlogsQuesByDate()throws Exception {
String sql = "SELECT title , date FROM (SELECT blog_title as title ,created_date as date FROM blog UNION SELECT ask_question as title , created_on as date FROM askquestions ) as aa ORDER BY date DESC";
List<Blog> blogs1 = getSession().createSQLQuery(sql).setResultTransformer(AliasToBeanResultTransformer).list();
System.out.println("blogs are===="+blogs1);
return blogs1;
}
Blog.java:
package com.bdisys.promorphics.domain;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@SuppressWarnings("serial")
@Entity
@Table(name="blog")
public class Blog extends BaseDomain {
@Column(name="blog_title")
private String blogTitle;
@Column(name="blog_text",columnDefinition="TEXT")
private String blogText;
@Enumerated(EnumType.STRING)
@Column(name="blog_status")
private Status blogStatus;
@OneToOne
@JoinColumn(name="created_by", nullable=false)
private User createdBy;
@OneToOne
@JoinColumn(name="blog_category", nullable=false)
private BlogCategory blogCategory;
@Temporal(TemporalType.DATE)
@Column(name="created_date")
private Date createdDate;
@Column(name="likes")
private Long likes;
@Column(name="uploads")
private String uploads;
@Column(name="youtube_link")
private String youTubeLik;
@Column(name="moderator_comment")
private String moderatorComment;
@Lob
@Column(name="blog_description")
private String blog_desc;
@ManyToOne
@JoinColumn(name="users")
private User users;
public User getUsers() {
return users;
}
public void setUsers(User users) {
this.users = users;
}
public String getBlog_desc() {
return blog_desc;
}
public void setBlog_desc(String blog_desc) {
this.blog_desc = blog_desc;
}
public String getBlogTitle() {
return blogTitle;
}
public void setBlogTitle(String blogTitle) {
this.blogTitle = blogTitle;
}
public String getBlogText() {
return blogText;
}
public void setBlogText(String blogText) {
this.blogText = blogText;
}
public Status getBlogStatus() {
return blogStatus;
}
public void setBlogStatus(Status blogStatus) {
this.blogStatus = blogStatus;
}
public User getCreatedBy() {
return createdBy;
}
public void setCreatedBy(User createdBy) {
this.createdBy = createdBy;
}
public BlogCategory getBlogCategory() {
return blogCategory;
}
public void setBlogCategory(BlogCategory blogCategory) {
this.blogCategory = blogCategory;
}
public Date getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
public Long getLikes() {
return likes;
}
public void setLikes(Long likes) {
this.likes = likes;
}
public String getUploads() {
return uploads;
}
public void setUploads(String uploads) {
this.uploads = uploads;
}
public String getYouTubeLik() {
return youTubeLik;
}
public void setYouTubeLik(String youTubeLik) {
this.youTubeLik = youTubeLik;
}
public String getModeratorComment() {
return moderatorComment;
}
public void setModeratorComment(String moderatorComment) {
this.moderatorComment = moderatorComment;
}
}
Askquestions.java:
package com.bdisys.promorphics.domain;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.IndexColumn;
@SuppressWarnings("serial")
@Entity
@Table(name="askquestions")
public class Askquestions extends BaseDomain {
@Column(length = 100, name = "id_subscribers")
private String idSubscribers;
@Column(length = 100, name = "is_anonymous")
private String isAnonymous;
@Column(length = 100, name = "display_name")
private String displayName;
@Temporal(TemporalType.DATE)
@Column(length = 100, name = "created_on")
private Date createdQuesOn;
@Lob
@Column(name = "ask_question")
private String askQuestion;
@Column(length = 100, name = "ask_to_whom")
private String askToWhom;
@Lob
@Column(name="question_of_day")
private String questionOfDay;
@ManyToOne
@JoinColumn(name="ask_category")
private Askcategory askcategory;
@ManyToOne
@JoinColumn(name="users")
private User users;
public User getUsers() {
return users;
}
public void setUsers(User users) {
this.users = users;
}
public Askcategory getAskcategory() {
return askcategory;
}
public void setAskcategory(Askcategory askcategory) {
this.askcategory = askcategory;
}
public String getQuestionOfDay() {
return questionOfDay;
}
public void setQuestionOfDay(String questionOfDay) {
this.questionOfDay = questionOfDay;
}
public String getIdSubscribers() {
return idSubscribers;
}
public void setIdSubscribers(String idSubscribers) {
this.idSubscribers = idSubscribers;
}
public String getIsAnonymous() {
return isAnonymous;
}
public void setIsAnonymous(String isAnonymous) {
this.isAnonymous = isAnonymous;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public String getAskQuestion() {
return askQuestion;
}
public void setAskQuestion(String askQuestion) {
this.askQuestion = askQuestion;
}
public String getAskToWhom() {
return askToWhom;
}
public void setAskToWhom(String askToWhom) {
this.askToWhom = askToWhom;
}
public Date getCreatedQuesOn() {
return createdQuesOn;
}
public void setCreatedQuesOn(Date createdQuesOn) {
this.createdQuesOn = createdQuesOn;
}
}
JSP page:
<tr>
<td style="border: 2px dotted #FFFFFF; border-radius:5px; background-color:#f3ecf0;">
<%
List<Blog> blog2 =new ArrayList<Blog>();
BlogDaoImpl blogDaoImpl1=new BlogDaoImpl();
blog2=blogDaoImpl1.getTopBlogsQuesByDate();
System.out.println(" Details of blogs are==="+blog2);
// Create two query strings for two sub HQLs
%>
<ul style="text-align: left; left:0px;font-size: 13px; margin-left:-20px; overflow-y: scroll; height:465px; list-style:url('images/arrows.png'); font-family:Palatino Linotype; color:#2a2a2a; border: 0px solid #d4d4d4" >
<%
for(int i=0;i<blog2.size();i++){
Blog blogs1=new Blog();
blogs1=blog2.get(i);
System.out.println("blogs size is===="+blog2.size());
blogs1.getId();
String paths="showblog/"+ blogs1.getBlogTitle()+"/"+blogs1.getId();
%>
<li style="border-bottom : 2px dotted #FFFFFF; margin-bottom: 10px;"><%=blogs1.getBlogTitle() %></li>
<%} %>
</ul>
</td>
</tr>
SELECT title, date
and casting toBlog
which is not possible. FetchBlog
object – Mustafa Genç Feb 20 at 12:20Blog
object – Mustafa Genç Feb 20 at 12:39