Hello.
I have a problem with executing query. So i have 2 tables in MySQL database:
Projects
create table projects(id int auto_increment primary key, projectName varchar(50) unique not null, shortDescription varchar(500) not null default "Default description of project", longDescription text, createTime timestamp default now())engine=innodb default charset=utf8;
and projectImg
create table projectImg (id int auto_increment primary key, imgName varchar(50) not null, imagePath varchar(20) not null default '../img', projectId int)engine=innodb default charset=utf8;
I try to get data from both of them using join and HQL:
Code:
[b]queryText = "from Projects p, ProjectImg pi where p.id = pi.projectId group by p.id order by p.id desc";[/b]
query = session.createQuery(queryText);
query.setMaxResults(3);
projectList = query.list();
application is deploying without errors, but when I will enter on my JSP page I see an exceptions:
Code:
org.apache.jasper.JasperException: java.lang.NumberFormatException: For input string: "imgName"
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:413)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
servlets.IndexServlet.doPost(IndexServlet.java:67)
servlets.IndexServlet.doGet(IndexServlet.java:44)
javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
filters.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:27)
root cause
java.lang.NumberFormatException: For input string: "imgName"
java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
java.lang.Integer.parseInt(Integer.java:481)
java.lang.Integer.parseInt(Integer.java:514)
javax.el.ArrayELResolver.toInteger(ArrayELResolver.java:375)
javax.el.ArrayELResolver.getValue(ArrayELResolver.java:195)
javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)
org.apache.el.parser.AstValue.getValue(AstValue.java:169)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:935)
org.apache.jsp.data.index_jsp._jspx_meth_c_005fforEach_005f0(index_jsp.java:149)
org.apache.jsp.data.index_jsp._jspService(index_jsp.java:110)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
servlets.IndexServlet.doPost(IndexServlet.java:67)
servlets.IndexServlet.doGet(IndexServlet.java:44)
javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
filters.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:27)
Here are hbm files:
Projects
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2012-10-10 00:41:09 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="mapsFiles.Projects" table="projects">
<id name="id" type="java.lang.Integer">
<column name="ID" />
<generator class="assigned" />
</id>
<property name="projectName" type="java.lang.String">
<column name="PROJECTNAME" />
</property>
<property name="shortDescription" type="java.lang.String">
<column name="SHORTDESCRIPTION" />
</property>
<property name="longDescription" type="java.lang.String">
<column name="LONGDESCRIPTION" />
</property>
<many-to-one name="pi" class="mapsFiles.ProjectImg"
not-null="true"
column="projectId"
fetch="join" />
</class>
</hibernate-mapping>
ProjectImg:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2012-10-10 00:41:09 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="mapsFiles.ProjectImg" table="projectImg">
<id name="id" type="java.lang.Integer">
<column name="ID" />
<generator class="assigned" />
</id>
<property name="imgName" type="java.lang.String">
<column name="IMGNAME" />
</property>
<property name="imgPath" type="java.lang.String">
<column name="IMGPATH" />
</property>
<property name="projectId" type="java.lang.Integer">
<column name="PROJECTID" />
</property>
</class>
</hibernate-mapping>
Projects mapping file:
Code:
package mapsFiles;
import java.text.SimpleDateFormat;
import org.hibernate.annotations.Entity;
import org.hibernate.annotations.Table;
/*create table projects(id int auto_increment primary key,
* projectName varchar(50) unique not null,
* shortDescription varchar(500) not null default "Default description of project",
* longDescription text,
* createTime timestamp default now())engine=innodb default charset=utf8; */
@Entity
@Table(appliesTo = "projects")
public class Projects {
private String projectName,shortDescription, longDescription;
private Integer id;
private ProjectImg pi;
public Projects(){
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getProjectName() {
return projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public String getShortDescription() {
return shortDescription;
}
public void setShortDescription(String shortDescription) {
this.shortDescription = shortDescription;
}
public String getLongDescription() {
return longDescription;
}
public void setLongDescription(String longDescription) {
this.longDescription = longDescription;
}
public ProjectImg getPi() {
return pi;
}
public void setPi(ProjectImg pi) {
this.pi = pi;
}
@Override
public String toString() {
return "Projects [projectName=" + projectName + ", shortDescription="
+ shortDescription + ", longDescription=" + longDescription
+ ", id=" + id + "Img=" +pi+"]";
}
}
and ProjectImg mapping file:
Code:
package mapsFiles;
import org.hibernate.annotations.Entity;
import org.hibernate.annotations.Table;
/*
* create table projectImg (id int auto_increment primary key,
* imgName varchar(50) not null,
* imagePath varchar(20) not null default '../img',
* projectId int)engine=innodb default charset=utf8;
*/
@Entity
@Table(appliesTo = "projectImg")
public class ProjectImg {
private String imgName, imgPath;
private Integer projectId, id;
public ProjectImg(){
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getImgName() {
return imgName;
}
public void setImgName(String imgName) {
this.imgName = imgName;
}
public String getImgPath() {
return imgPath;
}
public void setImgPath(String imgPath) {
this.imgPath = imgPath;
}
public Integer getProjectId() {
return projectId;
}
public void setProjectId(Integer projectId) {
this.projectId = projectId;
}
@Override
public String toString() {
return "ProjectImg [imgName=" + imgName + ", imgPath=" + imgPath
+ ", projectId=" + projectId + ", id=" + id + "]";
}
}
Could you give me some advice to solve this problem?
best regards and sorry for so much code...