I recently want to create a new project and use hibernate3.0 for persistence,
I downloaded hibernate-tools and used it to generate the pojo and map ing files. The source code is as follows:
Mysql5.0 database name used: hibernatetest
Table Structure:
Create Table 'cat '(
'Cat _ id' varchar (32) not null,
'Name' varchar (16) Character Set Latin1 not null default '',
'Sex' char (2) Character Set Latin1 default null,
'Weight' int (11) default null,
Primary Key ('cat _ id ')
) Engine = InnoDB default charset = gb2312
Cat. Java
Package com. First. pojo;
Import java. util .*;
Public class cat implements java. Io. serializable {
Private string catid;
Private string name;
Private string sex;
Private integer weight;
Public CAT (){
}
Public CAT (string catid ){
This. catid = catid;
}
Public String GETID (){
Return this. catid;
}
Public void setid (string catid ){
This. catid = catid;
}
Public String getname (){
Return this. Name;
}
Public void setname (string name ){
This. Name = Name;
}
Public String getsex (){
Return this. sex;
}
Public void setsex (string sex ){
This. Sex = sex;
}
Public integer getweight (){
Return this. weight;
}
Public void setweight (integer weight ){
This. Weight = weight;
}
}
Cat. HBM. xml
<? 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>
<! --
Auto-generated mapping file from
The hibernate.org has 2hbm Engine
-->
<Class name = "com. First. pojo. Cat" table = "cat" catalog = "hibernatetest">
<ID name = "ID" type = "string">
<Column name = "cat_id" length = "32"/>
<Generator class = "UUID. Hex"/>
</ID>
<Property name = "name" type = "string">
<Column name = "name" length = "16" not-null = "true"/>
</Property>
<Property name = "sex" type = "string">
<Column name = "sex" length = "2"/>
</Property>
<Property name = "weight" type = "integer">
<Column name = "weight"/>
</Property>
</Class>
</Hibernate-mapping>
Execution error:
SQL error: 1146, sqlstate: 42s02
1890 [main] Error util. jdbcexceptionreporter-base table or view not found, message from server: "Table 'hibernatetest. hibernatetest _ cat' doesn' t exist"
Table 'hibernatetest. hibernatetest _ cat'. If hibernatetest_cat's hibernatetest indicates the database, the previous hibernatetest. it indicates that the database is duplicated. Therefore, if the table cannot be found, a catalog = "hibernatetest" ing file does not know what to do, and the database name is deleted, it's normal, alas! I went there again for half a day, Dizzy !!!