The essence of the problem:

SEVERE: Servlet.service () for servlet [dispatcher] in context with path [/ Air] threw exception [Request processing failed; nested exception is org.hibernate.InstantiationException: No default constructor for entity: chpt.db.model.Students] with root cause org.hibernate.InstantiationException: No default constructor for entity: chpt.db.model.Students

application-Context.xml

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <context:annotation-config/> <context:component-scan base-package="chpt"/> <context:component-scan base-package="chpt.db.model"/> <!-- import the dataSource definition <import resource="applicationContext-dataSource.xml"/>--> <import resource="applicationContext-dataSource.xml"/> <bean class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" id="sessionFactory"> <property name="dataSource" ref="dataSource"/> <property name="mappingResources"> <list> <!-- <value>/chpt/db/hibernate-mapping.hbm.xml</value> --> </list> </property> <property name="annotatedClasses"> <list> <value>chpt.db.model.Airport</value> <value>chpt.db.model.Flight</value> <value>chpt.db.model.Movement_flights</value> <value>chpt.db.model.Passenger</value> <value>chpt.db.model.Plane</value> <value>chpt.db.model.Students</value> </list> </property> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.HSQLDialect hibernate.show_sql=true </value> </property> </bean> <bean class="org.springframework.orm.hibernate3.HibernateTransactionManager" id="transactionManager" p:sessionFactory-ref="sessionFactory"/> <bean class="chpt.Controller.IndexController" id="dbUtil"/> </beans> 

DbUtil.java

 package chpt.db; import java.util.*; import org.hibernate.Hibernate; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.orm.hibernate3.HibernateTemplate; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import chpt.db.model.*; //import chpt.db.model.*; @Repository @Transactional public class DBUtil { Configuration config; private SessionFactory sf; private Session session; @Autowired public DBUtil(SessionFactory sessionFactory) { sf = sessionFactory; session = sf.openSession(); } public void save(Object obj) { session.beginTransaction(); session.clear(); session.save(obj); session.getTransaction().commit(); } public void update(Object obj) { session.beginTransaction(); session.clear(); session.update(obj); session.getTransaction().commit(); } public void dell(Object obj) { session.beginTransaction(); session.clear(); session.delete(obj); session.getTransaction().commit(); } public List<Students> getStudents(){ return session.createQuery("from chpt.db.model.Students").list(); } 

IndexController.java

 package chpt.Controller; import java.util.List; import javax.servlet.http.*; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import chpt.db.*; import chpt.elements.TableHtml; import chpt.db.model.*; import chpt.elements.*; @Controller @RequestMapping("/index.htm") public class IndexController { ModelAndView modelAndView; private final DBUtil dbUtil; TableHtml adapterManager; String namePage; String attributeTabelName; @Autowired public IndexController(DBUtil dbUtil) { this.dbUtil = dbUtil; adapterManager = null; namePage = "index"; attributeTabelName = "tabel"; } @RequestMapping(params="Lab3", method=RequestMethod.GET) protected void viewStudents(HttpServletRequest request, HttpServletResponse response) throws Exception { List<Students> data = dbUtil.getStudents(); adapterManager = new TableStudents(data); response.setContentType("text/plain"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(adapterManager.CreateView()); } } 

Students.java

 package chpt.db.model; import java.text.ParseException; import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; import chpt.db.Tabels; @Entity @Table(name = "students") public class Students extends chpt.db.AbstractTableModel { @Id @GeneratedValue @Column(name = "id") int id; @Column(name = "first_name") String first_name; @Column(name = "last_name") String last_name; @Column(name = "birthday") Date birthday; @Column(name = "faculty") int faculty; public Students(Tabels typeTabel) { typeTabel = Tabels.Students; } public String getFirst_name() { return first_name; } public void setFirst_name(String first_name) { this.first_name = first_name; } public String getLast_name() { return last_name; } public void setLast_name(String last_name) { this.last_name = last_name; } public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; } public int getFaculty() { return faculty; } public void setFaculty(int facult) { this.faculty = facult; } public int getId() { return id; } public void setId(int id) { this.id = id; } @Override public void setAll(Object[] obj) throws ParseException { id = Integer.parseInt((String) obj[0]); } } 

I do not know what to do, because I would not post here. All paths are spelled correctly, for several days I cannot deal with this problem.

  • 2
    Brilliant question - Barmaley
  • For some reason, @Autowired does not initialize DbUtil for Students and, well, along the chain ... As is clear from an error. Dear Barmaley! If I knew what was wrong, I would not write here. So excuse me, I can’t teach on the dish. - smail2133
  • 2
    @Smail2133 you would like to start: 1) format the code 2) separate the "wheat from the chaff", that is, at least formulate the question, namely, write that it does not work? Did you yourself read your question? 3) The question should just be "on a silver platter" - clear, clear. You don't have a question - there is no “Battle of Psychics” here - there are no people capable of guessing what you wanted. - Barmaley
  • 3
    @ smail2133: really, bother to throw out all unnecessary things from the question. You only have an error message takes up half the screen, read it yourself and leave only the desired part. Create a mini-project that reproduces the problem. Remove all fields from the database, except for one. Remove the getters and setters, they are definitely irrelevant. If you don’t do this, we’ll have to do this for you to answer your question. And we are just as lazy as you, maybe even more - you have a problem. - VladD
  • I deleted my answer, because it does not correspond to the question I join the indignant above. Finding the problem for you, and even when changing symptoms, is extremely difficult. - a_gura

1 answer 1

The answer to your question is contained in the error message that you gave:

org.hibernate.InstantiationException: No default constructor for entity: chpt.db.model.Students

Apparently, you could not translate this message. It says here that for the class chpt.db.model.Students there is no default constructor (in other words, the constructor with no arguments).

Usually this constructor is created by the compiler (implicitly and automatically), but only then when you have not declared it (or any other constructor) yourself. In your case, the Students class already has a constructor:

 public Students(Tabels typeTabel) { typeTabel = Tabels.Students; } 

Therefore, there are two options - either add a constructor with no arguments, or remove this (so that the compiler creates a default constructor for you).

(The spring tag, as well as the listings of the application-Context.xml , DbUtil.java and IndexController.java can be removed from the question, because they have no relation to it. In the listing of the Students.java file, the getters and setters can also be omitted, to make the question shorter and clearer.)