休眠 - 它改变了数据库的结构吗? [英] Hibernate - does it change the structure of a database?

查看:100
本文介绍了休眠 - 它改变了数据库的结构吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Spring上用java构建了一个更大的项目,很多人都劝我,使用hibernate来缓解对数据库的访问。问题是,我不得不使用该项目以前版本的数据库,这个版本以前是用PHP编写的,所以他们没有使用hibernate。我已经阅读了关于hibernate的一些信息,但我仍然不确定是否需要更改数据库的结构,或者是否可以使用标准MySQL数据库和int,varchar和其他类型的存储值,并使用hibernate在我的java代码中摆脱大量的SQL?

解决方案

虽然Hibernate可以用来创建/删除表,在生产环境中不会那样做。在这些场景中,您正在定义POJOS和底层数据库模式之间的对象关系映射。所以,实际上,Hibernate不需要向数据库模式添加任何东西。



如果您正在使用在应用hibernate之前定义的架构,那么您可能需要以确保字段转换器是合适的(即Hibernate可能对SQL中的列类型构成日期或数字有不同的想法),但这意味着您必须提供显式映射/转换器,而不是使用默认值。 / p>

但是,您应该可以在不对现有数据库模式进行任何重大更改的情况下使用Hibernate。


I'm building bigger project in java on Spring and lot of people have adviced me, to use hibernate to ease access to the database. The problem is,that I have to use database from previous version of this project, which used to be written in PHP, so they didn't use hibernate for sure. I've read something about hibernate, but I'm still not sure in one thing - does it have to change the structure of the database or can I use standard MySQL database with stored values in int, varchar and other types and use hibernate just to get rid of lot of SQL in my java code?

解决方案

While Hibernate can be used to create / delete tables, typically you wouldn't do that in a production environment. In these scenarios, you're defining the Object-Relational Mapping between the POJOS and the underlying database schema. So, really, Hibernate doesn't need to add anything to the database schema.

If you're working with a Schema which was defined before applying hibernate, you probably need to ensure the field converters are appropriate (ie, Hibernate might have different ideas about what column type in SQL constitutes a date or a number), but that means that you would have to provide the explicit mapping/converter instead of using the default.

But, you should be able to use Hibernate without making any major changes to the existing database schema.

这篇关于休眠 - 它改变了数据库的结构吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆