说说hibernate4.1以后仲么就把xml映射给拿掉了,瞎了。

angelosy 2013-07-09 09:17:37
不解,现在的数据库都向着支持xml的方向发展,。
...全文
220 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
suciver 2013-07-12
  • 打赏
  • 举报
回复
hibernate4一样支持,只是现在都用注解了,开发起来快而且不需要向配置xml那么多了
melodyfair1971 2013-07-11
  • 打赏
  • 举报
回复
引用 3 楼 oymaidi 的回复:
引用 1 楼 melodyfair1971 的回复:
怎么会。。我还用着呢,hibernate 4.2.3
我可能没说明白,我说的xml映射是pojo和数据库的xml字段的映射。你确定你懂这个,可以教教我了,谢谢了
支持的。最新版本 hibernate 4.2.3。jar包用官方下载里面的required文件夹里面的
<?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>
angelosy 2013-07-11
  • 打赏
  • 举报
回复
引用 2 楼 fanslate 的回复:
注解出来以后很多的框架都提供了注解的配置方式,一些跟实体类相关的配置用注解配置起来要简洁的多,具体的你用两种方式对比几次就能明白
我可能没说明白,我说的xml映射是pojo和数据库的xml字段的映射。
angelosy 2013-07-11
  • 打赏
  • 举报
回复
引用 1 楼 melodyfair1971 的回复:
怎么会。。我还用着呢,hibernate 4.2.3
我可能没说明白,我说的xml映射是pojo和数据库的xml字段的映射。你确定你懂这个,可以教教我了,谢谢了
byourfan 2013-07-09
  • 打赏
  • 举报
回复
注解出来以后很多的框架都提供了注解的配置方式,一些跟实体类相关的配置用注解配置起来要简洁的多,具体的你用两种方式对比几次就能明白
melodyfair1971 2013-07-09
  • 打赏
  • 举报
回复
怎么会。。我还用着呢,hibernate 4.2.3

23,404

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧