In the consolidation spring+hibernate times this error, the Sessionfactory configuration is as follows:
<BeanID= "Sessionfactory"class= "Org.springframework.orm.hibernate4.LocalSessionFactoryBean">.......<!--Hibernate class files that are configured automatically by scanning annotations - < Propertyname= "Packagestoscan">//Last found to be a mistake at the place <List> <value>Sys.model</value> </List> </ Property>
....... </Bean>
As in the XML configuration above, Packagetoscan is configured to configure the Hibernate class in an annotated manner, as in the following way:
Package Sys.model;import Java.io.serializable;import Java.util.date;import javax.persistence.column;import Javax.persistence.entity;import Javax.persistence.id;import Javax.persistence.table;import Javax.persistence.temporal;import Javax.persistence.TemporalType;@Entity @table (name = "User")public class UserInfo implements Serializable {private static final long serialversionuid = 8427996478439081619L; fields private String ID; private String name; Private String pwd; Private Date Createdatetime; Private Date Modifydatetime; /** Full Constructor */public UserInfo (string ID, string name, string pwd, date createdatetime, date modifydatetime) { This.id = ID; THIS.name = name; This.pwd = pwd; This.createdatetime = Createdatetime; This.modifydatetime = Modifydatetime; }@Id @Column (name = "Id", unique = true, Nullable = false, Length = $)Public String GetId () {return this.id; } public void SetId (String id) {this.id = ID; }@Column (name = "Name", unique = true, Nullable = false, length = +)Public String GetName () {return this.name; } public void SetName (String name) {this.name = name; }@Column (name = "PWD", nullable = false, length = +)Public String getpwd () {return this.pwd; } public void SetPwd (String pwd) {this.pwd = pwd; } @Temporal (Temporaltype.timestamp)//If this is the temporaltype.date, then the time is stored in the database will be "2015-07-16 00:00:00" This form, time and seconds are zero @ Column (name = "Createdatetime", length = 7) public Date Getcreatedatetime () {return this.createdatetime; } public void Setcreatedatetime (Date createdatetime) {this.createdatetime = Createdatetime; } @Temporal (Temporaltype.timestamp) @Column (name = "Modifydatetime", length = 7) public Date Getmodifydatetime () {return this.modifydatetime; } public void Setmodifydatetime (Date modifydatetime) {this.modifydatetime = Modifydatetime; } @Override Public String toString () {return ' [ID: ' + ID + ' name: ' + name + ' PassWord: ' + pwd + ' Createda Tetime: "+ createdatetime +" Modifydatetiem: "+ modifydatetime +"] "; }}
But the way I used to integrate the *.hbm.xml
The most convenient way to do this is to use "mappingdirectorylocations"
<BeanID= "Sessionfactory"class= "Org.springframework.orm.hibernate3.LocalSessionFactoryBean">.......< Propertyname= "Mappingdirectorylocations"> <List> <value>Classpath:com/vrv/paw/domain</value> </List> </ Property>
</Bean>
Extended:
Mappingresources, Mappinglocations, mappingdirectorylocations
The difference between them:
1. Mappingresources: Specify the specific mapping file name under Classpath
<name= "mappingresources"> <value ></value> </Property>
2. Mappinglocations: You can specify any file path, and you can specify a prefix: classpath, file, and so on
< property name = "Mappinglocations" > Span style= "color: #0000ff;" >< value > /web-inf/ Petclinic.hbm.xml </ > </ property >
<name= "mappinglocations"> <value ></value> </Property>
You can also specify by using a wildcard character, ' * ' to specify a file (path) name, ' * * ' to specify multiple file (path) names, for example:
<name= "mappinglocations"> <value ></value> </Property>
The above configuration is the Hbm.xml file under any maps path under the Com/company/domain package is loaded as a mapping file
3. Mappingdirectorylocations: Specifying the mapped file path
<name= "mappingdirectorylocations"> <List > <value>web-inf/hibernatemappings</ value > </ List > </ Property >
You can also use Classpath to point out
< property name = "Mappingdirectorylocations" < list > < value > classpath:/xxx/package/</ Value > </ list > </ property >
Summary: Annotated mode configuration of the Hibernate class and *.hbm.xml mode configuration of the class, configuration Sessionfactory when configured in a different way, which I did not notice before
No persistent classes found for query Class:from Com.vrv.paw.domain.User