这是myeclipse10自动生成的配置文件表category映射
我试了在数据库窗口里能插入
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="cn.itcast.shop.pojo.Category" table="category" catalog="shop">
<id name="cid" type="java.lang.Integer">
<column name="cid" />
<generator class="native"></generator>
</id>
<property name="ctype" type="java.lang.String">
<column name="ctype" length="20" />
</property>
<property name="chot" type="java.lang.Boolean">
<column name="chot" />
</property>
<property name="aid" type="java.lang.Integer">
<column name="aid" />
</property>
</class>
</hibernate-mapping>
这是表的类文件,也是自动生成的
package cn.itcast.shop.pojo;
/**
* AbstractCategory entity provides the base persistence definition of the
* Category entity. @author MyEclipse Persistence Tools
*/
public abstract class AbstractCategory implements java.io.Serializable {
// Fields
private Integer cid;
private String ctype;
private Boolean chot;
private Integer aid;
// Constructors
/** default constructor */
public AbstractCategory() {
}
/** full constructor */
public AbstractCategory(String ctype, Boolean chot, Integer aid) {
this.ctype = ctype;
this.chot = chot;
this.aid = aid;
}
// Property accessors
public Integer getCid() {
return this.cid;
}
public void setCid(Integer cid) {
this.cid = cid;
}
public String getCtype() {
return this.ctype;
}
public void setCtype(String ctype) {
this.ctype = ctype;
}
public Boolean getChot() {
return this.chot;
}
public void setChot(Boolean chot) {
this.chot = chot;
}
public Integer getAid() {
return this.aid;
}
public void setAid(Integer aid) {
this.aid = aid;
}
}
package cn.itcast.shop.pojo;
/**
* Category entity. @author MyEclipse Persistence Tools
*/
public class Category extends AbstractCategory implements java.io.Serializable {
// Constructors
/** default constructor */
public Category() {
}
/** full constructor */
public Category(String ctype, Boolean chot, Integer aid) {
super(ctype, chot, aid);
}
}
这是hibernater的配置文件
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="myeclipse.connection.profile">mysql</property>
<!--
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
-->
<property name="show_sql">true</property>
<mapping resource="cn/itcast/shop/pojo/Category.hbm.xml" />
</session-factory>
</hibernate-configuration>
表结构:

这是我写的测试类:
package cn.itcast.ssh;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.orm.hibernate3.HibernateTemplate;
import cn.itcast.oneday.service.impl.CategoryServiceImpl;
import cn.itcast.shop.pojo.Category;
public class SSHTest {
@Test
public void spring(){
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-*.xml");
System.out.println(context.getBean("date"));
}
@Test
public void hibernate(){
System.out.println(HibernateSessionFactory.getSession());
}
@Test
public void springHibernate(){
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-*.xml");
CategoryServiceImpl categoryServiceImpl=(CategoryServiceImpl)context.getBean("categoryServiceImpl");
Category category = new Category("test",false,1);
categoryServiceImpl.save(category);
}
}
我试了在数据库窗口里能插入
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="cn.itcast.shop.pojo.Category" table="category" catalog="shop">
<id name="cid" type="java.lang.Integer">
<column name="cid" />
<generator class="native"></generator>
</id>
<property name="ctype" type="java.lang.String">
<column name="ctype" length="20" />
</property>
<property name="chot" type="java.lang.Boolean">
<column name="chot" />
</property>
<property name="aid" type="java.lang.Integer">
<column name="aid" />
</property>
</class>
</hibernate-mapping>
这是表的类文件,也是自动生成的
package cn.itcast.shop.pojo;
/**
* AbstractCategory entity provides the base persistence definition of the
* Category entity. @author MyEclipse Persistence Tools
*/
public abstract class AbstractCategory implements java.io.Serializable {
// Fields
private Integer cid;
private String ctype;
private Boolean chot;
private Integer aid;
// Constructors
/** default constructor */
public AbstractCategory() {
}
/** full constructor */
public AbstractCategory(String ctype, Boolean chot, Integer aid) {
this.ctype = ctype;
this.chot = chot;
this.aid = aid;
}
// Property accessors
public Integer getCid() {
return this.cid;
}
public void setCid(Integer cid) {
this.cid = cid;
}
public String getCtype() {
return this.ctype;
}
public void setCtype(String ctype) {
this.ctype = ctype;
}
public Boolean getChot() {
return this.chot;
}
public void setChot(Boolean chot) {
this.chot = chot;
}
public Integer getAid() {
return this.aid;
}
public void setAid(Integer aid) {
this.aid = aid;
}
}
package cn.itcast.shop.pojo;
/**
* Category entity. @author MyEclipse Persistence Tools
*/
public class Category extends AbstractCategory implements java.io.Serializable {
// Constructors
/** default constructor */
public Category() {
}
/** full constructor */
public Category(String ctype, Boolean chot, Integer aid) {
super(ctype, chot, aid);
}
}
这是hibernater的配置文件
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="myeclipse.connection.profile">mysql</property>
<!--
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
-->
<property name="show_sql">true</property>
<mapping resource="cn/itcast/shop/pojo/Category.hbm.xml" />
</session-factory>
</hibernate-configuration>
表结构:

这是我写的测试类:
package cn.itcast.ssh;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.orm.hibernate3.HibernateTemplate;
import cn.itcast.oneday.service.impl.CategoryServiceImpl;
import cn.itcast.shop.pojo.Category;
public class SSHTest {
@Test
public void spring(){
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-*.xml");
System.out.println(context.getBean("date"));
}
@Test
public void hibernate(){
System.out.println(HibernateSessionFactory.getSession());
}
@Test
public void springHibernate(){
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-*.xml");
CategoryServiceImpl categoryServiceImpl=(CategoryServiceImpl)context.getBean("categoryServiceImpl");
Category category = new Category("test",false,1);
categoryServiceImpl.save(category);
}
}