23,404
社区成员
发帖
与我相关
我的任务
分享<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated 2013-7-7 14:17:44 by Hibernate Tools 4.0.0 -->
<hibernate-mapping>
<class name="hibernate.pojo.Apple" table="apple" catalog="hibernate">
<id name="id" type="int">
<column name="ID" />
<generator class="increment" />
</id>
<many-to-one name="fruit" class="hibernate.pojo.Fruit" fetch="select">
<column name="FRIUT_ID" not-null="true" />
</many-to-one>
<property name="name" type="string">
<column name="NAME" length="20" not-null="true" />
</property>
</class>
</hibernate-mapping>
package hibernate.pojo;
// default package
// Generated 2013-7-7 14:17:44 by Hibernate Tools 4.0.0
/**
* Apple generated by hbm2java
*/
public class Apple implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private int id;
private Fruit fruit;
private String name;
public Apple() {
}
public Apple(Fruit fruit, String name) {
this.fruit = fruit;
this.name = name;
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public Fruit getFruit() {
return this.fruit;
}
public void setFruit(Fruit fruit) {
this.fruit = fruit;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.search.autoregister_listeners">false</property>
<mapping resource="hibernate/pojo/Vegetable.hbm.xml" />
<mapping resource="hibernate/pojo/Tomato.hbm.xml" />
<mapping resource="hibernate/pojo/Apple.hbm.xml" />
<mapping resource="hibernate/pojo/Fruit.hbm.xml" />
<mapping resource="hibernate/pojo/Food.hbm.xml" />
</session-factory>
</hibernate-configuration>注解出来以后很多的框架都提供了注解的配置方式,一些跟实体类相关的配置用注解配置起来要简洁的多,具体的你用两种方式对比几次就能明白
怎么会。。我还用着呢,hibernate 4.2.3