| |

VerySource

 Forgot password?
 Register
Search
View: 802|Reply: 3

Let's take a look at this hibernate problem. !! !!

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-2 17:10:01
| Show all posts |Read mode
Define the class as:
public class aa
{
  private int id;
  private String name;
  private int sort;
  public aa ()
  {
  }
  public void setId (int Id)
  {
    this.id = Id;
  }
  public int getId ()
  {
    return this.id;
  }
  public void setSort (int Sort)
  {
    this.sort = Sort;
  }
  public int getSort ()
  {
    return this.sort;
  }
  public void setName (String Name)
  {
    this.name = Name;
  }
  public String getName ()
  {
    return this.name;
  }
}

The xml file is configured as:
<? xml version = "1.0"?>
<! DOCTYPE hibernate-mapping PUBLIC
                            "-// Hibernate / Hibernate Mapping DTD 3.0 // EN"
                            "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package = "......">
  <class name = "aa" table = "t_aa">
    <id name = "Id">
      <generator class = "native" />
    </ id>
    <property name = "Name" />
    <property name = "Sort" />
   </ class>
</ hibernate-mapping>
The trace exceptions in the debug state are:
"Could not prase mapping document from resource aa.hbm.xml"
"class aa not found while looking for property: Id"

The end error page is:
HTTP Status 500-type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException
 org.apache.jasper.servlet.JspServletWrapper.service (JspServletWrapper.java:370)
 org.apache.jasper.servlet.JspServlet.serviceJspFile (JspServlet.java:291)
 org.apache.jasper.servlet.JspServlet.service (JspServlet.java:241)
 javax.servlet.http.HttpServlet.service (HttpServlet.java:802)
root cause java.lang.NullPointerException
 com.sudytech.hibernate.HibernateFactory.currentSession (HibernateFactory.java:49)
 org.apache.jsp.test_jsp._jspService (org.apache.jsp.test_jsp: 60)
 org.apache.jasper.runtime.HttpJspBase.service (HttpJspBase.java:97)
 javax.servlet.http.HttpServlet.service (HttpServlet.java:802)
 org.apache.jasper.servlet.JspServletWrapper.service (JspServletWrapper.java:322)
 org.apache.jasper.servlet.JspServlet.serviceJspFile (JspServlet.java:291)
 org.apache.jasper.servlet.JspServlet.service (JspServlet.java:241)
 javax.servlet.http.HttpServlet.service (HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat / 5.5.9 logs.Apache Tomcat / 5.5.9


Please enlighten heroes, urgent! !! !! !!
Reply

Use magic Report

1

Threads

21

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 China

Post time: 2020-1-2 20:33:01
| Show all posts
<id name = "Id"> <---------------- Renamed the same property as pojo. (id)
Reply

Use magic Report

1

Threads

51

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2020-1-3 09:42:01
| Show all posts
"Could not prase mapping document from resource aa.hbm.xml"
"class aa not found while looking for property: Id"
 <id name = "Id">
      <generator class = "native" />
    </ id>
As LS said, if it doesn't work, change it to
 <id name = "Id">
         </ id>
Reply

Use magic Report

0

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-5 20:15:01
| Show all posts
Originally, your id type is incorrect. When writing Pojo classes, you should write your id type as Long. This is the specification for writing Pojo classes.
Also, the attributes in the mapping file must be the same as those in pojo
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list