Recently will often use Hibernate, also often error, look at the screen a big red bar is very uncomfortable, these days gathered a bit of often reported errors, integration of a down here, and then the mistake to solve the problem directly
1, org.hibernate.exception.ConstraintViolationException:could not execute statement
This is the lowest error, at the beginning of the entity class to set a private property ID, the definition of an int, then a think wrong, changed to an integer, but the back of the Get and set method inside the data type did not change, reported this error, but this data type although not the same, But all of them belong to a parent class, and eclipse will not give you an error, but it's easy to look at it more carefully.
2, Org.hibernate.MappingException:Unknownentity, (translated by unknown entities)
Look at the literal meaning should also know is the entity class out of the question, but ... is not the entity class problem, has already said Mappingexception, because this project practice needs to do a few classes of mapping, in the Hibernate.cfg.xml configuration file I put <mapping> tag to comment out, So this is a configuration file problem, but also a very low-level error
3, Org.hibernate.MappingException:An Association from the table PRODUCT refers to an unmapped CLASS:COM.HANQI.DAO.FA Ctory
Again a configuration mapping file problem, then typing too fast, so that <many-to-one name= "Factoryid" class= "com.hanqi.dao.Factory" > This tag's class is wrong, Originally should be factory, but I wrote the factory, the system does not know, so throws this exception
4, org.hibernate.InstantiationException:No default constructor for Entity:com.hanqi.dao.Factory
This error is I deliberately committed, because the creation of the entity class must be accompanied by a default empty construction method, I deliberately did not write, want to see what error will be reported, the result in the run to the query statement thrown this exception, and then I know that the original does not write an empty construction method will really error
One thing to note here is that if there is a constructor with the parameter in the entity class, the empty constructor must be added, and if there is no constructor with parameters, then this default is not added
5, Java.lang.ClassCastException:java.lang.String cannot is cast to [Ljava.lang.Object
This error is a very strange error, the code is not wrong, the code logic is not wrong, the entity class, configuration files are not wrong, even eclipse and the database open way is not wrong, but he is an error, as for the reasons I do not know, but I guess, The reason for this error is because my HQL query statement has a SELECT, and there is only one field behind the Select, and if you add two fields or add a count (1), I infer that when there is only one field behind the Select, The system automatically transforms the returned result into an object, not an array of objects, because we all know that it is good to traverse the collection directly with the object when there are multiple fields behind the select that need to traverse two times, the first traversal of the collection, the second pass-through group, and only one field behind the Select.
Hibernate often reported a few of the humble mistakes, all because of careless or hand slip caused by the wrong input