-->
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: Many to one and NumberFormatException
PostPosted: Sat Oct 13, 2012 10:19 am 
Newbie

Joined: Sat Sep 08, 2012 9:58 am
Posts: 5
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...


Top
 Profile  
 
 Post subject: Re: Many to one and NumberFormatException
PostPosted: Sat Oct 13, 2012 1:54 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
I don't see how your issue relates to Hibernate. You obviously mapped some string, and you're getting a string. This is sent to some other framework by your code or some page fragment evaluation where an integer is expected.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Many to one and NumberFormatException
PostPosted: Sat Oct 13, 2012 6:37 pm 
Newbie

Joined: Sat Sep 08, 2012 9:58 am
Posts: 5
if you meant SiteMesh as "some other framework" - it's only a jsp page decorator, which is used by every JSP page, it's not related with the issue. I have mapped an imgName as String, and I don't know why it wants int ? I can't resolve that issue. I'm not trying to set an imgName with int value, I only try to get the list from the query - which throws that exception. If I will delete the

Code:
queryText = "from Projects p, ProjectImg pi where p.id = pi.projectId group by p.id order by p.id desc";
      query = session.createQuery(queryText);
      query.setMaxResults(3);
      projectList = query.list();


I don't get an exception - so that's why I have posted this here, on hibernate forum. I don't do anything with the query result, I only dispatch it to the jsp page.


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.