利用Hibernate映射文件生oracle或者mysql数据库
2011-06-01 10:46
302 查看
(一)利用hibernate影射文件在oracle中生成对应的数据库和表
我用的是hibernate和Spring配置生成的,在Spring的配置文件配置如下:
启动项目时即可在oracle中生成数据库。
(二)利用hibernate影射文件在mysql中生成对应的数据库和表
①同样利用hibernate和Spring配置生成,在session-factory中的配置如下:
②需要写一个main方法,代码如下:
注意:需要先在数据库中建一个名字是xdatabasename的空数据库。
我用的是hibernate和Spring配置生成的,在Spring的配置文件配置如下:
<!-- 配置sessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="mappingDirectoryLocations"> <list> <value>classpath:/standing/common/pojo/hbm/</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.OracleDialect </prop> <prop key="hibernate.jdbc.batch_size">25</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">validate</prop> </props> </property> </bean>
启动项目时即可在oracle中生成数据库。
(二)利用hibernate影射文件在mysql中生成对应的数据库和表
①同样利用hibernate和Spring配置生成,在session-factory中的配置如下:
<session-factory> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="connection.url"> jdbc:mysql://localhost:3306/xdatabasename </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"> myDriver </property> <property name="jdbc.use_scrollable_resultset">false</property> <property name="hibernate.connection.pool.size">20</property> <property name="hibernate.show_sql">true</property> <property name="jdbc.fetch_size">50</property> <property name="jdbc.batch_size">25</property> <property name="format_sql">true</property> <property name="show_sql">true</property> <mapping resource="XX/po/X.hbm.xml" /> </session-factory>
②需要写一个main方法,代码如下:
package xX.test; import org.hibernate.cfg.Configuration; import org.hibernate.tool.hbm2ddl.SchemaExport; public class CreateDatabase { public static void main(String[] args) { Configuration cfg = new Configuration().configure(); SchemaExport schemaExport= new SchemaExport(cfg); schemaExport.create(false, true); } }
注意:需要先在数据库中建一个名字是xdatabasename的空数据库。
相关文章推荐
- 利用Hibernate映射文件生oracle或者mysql数据库
- 利用hibernate配置文件逆向映射数据库表
- 在MyEclipse中利用XDoclet自动生成Hibernate配置和映射文件
- JAVA_WEB项目之在myecplise中如何利用DB Browser窗口连接mysql数据库之后根据表反向生成映射文件
- MyEclipse6.5利用Hibernate逆向工程生成映射文件出现oracle数据库版本不兼容解决
- 利用Ant和Xdoclet从pojo类生成hibernate的映射文件并生成hibernate的配置文件
- 利用hibernate映射文件生成表
- Hibernate:利用HibernateTools和ANT自动构建hibernate对象、映射文件、表之间的转换
- 使用oracle数据库和MySQL数据库时hibernate的映射文件.hbm.xml的不同
- 利用MyEclipse的ant插件生成Hibernate的映射文件
- Eclipse快速上手Hibernate--2. 利用Hbm映射文件开发
- 利用ant和XDOCLET生成Hibernate3配置文件和映射文件的BUILD.XML
- Eclipse快速上手Hibernate--2. 利用Hbm映射文件开发
- Hibernate映射文件中对应的mysql数据库表字段的类型
- 利用MyEclipse的ant插件生成Hibernate的映射文件
- 利用hibernate的映射文件,自动生成oracle数据库表
- 使用oracle数据库和MySQL数据库时hibernate的映射文件.hbm.xml的不同
- Eclipse快速上手Hibernate--2. 利用Hbm映射文件开发(摘自javamxj的blog)
- Eclipse快速上手Hibernate--2. 利用Hbm映射文件开发
- spring(2.5或者3.2)集成hibernate3.5的配置文件