Unable to locate appropriate constructor on Class__java

Source: Internet
Author: User

Usually we like to encapsulate HQL query results into Pojo objects
Syntax
Select New POJO (Id,name) from POJO;

Unable to locate appropriate constructor on class
This encapsulation requires the POJO class to provide the corresponding constructor, the POJO (id,name) construction method.

However, this exception is often thrown in use: unable to locate appropriate constructor on class.

This exception requires several things to check:
1 parameter constructor is the correct argument type
2 The order of the parameter constructors is consistent with the order in the HQL
3 The number of parameters of the parameter constructor is the same as the number of HQL
4 whether the parameter type of the parameter constructor is timestamp

The 4th one is more complex.

This provides the parameter type of the parameter constructor as a timestamp solution:
Super.gethibernatetemplate (). Find ("Select the new Student (id,name,date) from Student");

Entity class:
public class Student {
private Long ID;
private string name;
private string address;
Private Timestamp date;
Public Long getId () {
   return id;
}
public void setId (Long id) {
   this.id = ID;
}
Public String GetName () {
   return name;
}
public void SetName (String name) {
   this.name = name;
}
Public String getaddress () {
   return address;
}
public void setaddress (String address) {
   this.address = address;
}
Public Timestamp getDate () {
   return date;
}
public void Setdate (timestamp date) {
   this.date = date;
}
Public Student () {
   super ();
}

Pay attention to some of the construction methods
Public Student (Long ID, String name, Object date) {
This.id=id;
THIS.name = name;
This.date = Stringtotimestamp (date.tostring ());
}


public static Timestamp Stringtotimestamp (String datestr) {

SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
Calendar cal = Calendar.getinstance ();
try {
Date date = Sdf.parse (DATESTR);
Date.gettime ();
Cal.settime (date);
return new Timestamp (Cal.gettimeinmillis ());
catch (ParseException e) {
E.printstacktrace ();
}

Cal.settime (New Date ());
return new Timestamp (Cal.gettimeinmillis ());
}
}

Origin: Http://blog.sina.com.cn/staratsky

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.