使用Hibernate进行代码优先处理 [英] Code First Apprach with Hibernate

查看:64
本文介绍了使用Hibernate进行代码优先处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是学习Java/Spring MVC/Hibernate的PHP开发人员.我想知道Hibernate是否支持像实体这样的代码优先方法是ASP.NET还是带有PHP的Doctrine.到目前为止,我所见过的所有资源(如果先创建数据库然后再编写类和XML文件)都是如此.是否可以先使用Hibernate编写代码,然后它生成数据库并处理架构更改?如果可以的话,有人可以将我链接到解释此操作方式的资源吗?预先感谢.

I am a PHP Developer in the process of learning Java / Spring MVC / Hibernate. I was wondering if Hibernate supported Code First Approach like Entity is ASP.NET or Doctrine with PHP. All the resources I have seen so far the database if being created first and then you write your classes and XML files. Is it possible to do code first with Hibernate and it generates the database and handles the schema changes? If so can someone link me to a resource explaining how this is done? Thanks in advance.

我在考虑它时,Hibernate也可以基于现有架构生成代码吗?

While I'm thinking about it can Hibernate generate the code based on an existing schema too?

推荐答案

您正在寻找非常古老的资源.您要使用的是JPA 2;它非常牢固地基于Hibernate,并且Hibernate可以作为JPA提供程序运行.使用类似于实体框架的JPA,您可以创建POJO并注释其字段,以向JPA提供程序提供有关如何处理持久性的指令.

You're looking at very old resources. What you want to use instead is JPA 2; it's very strongly based on Hibernate, and Hibernate can run as a JPA provider. With JPA, which is similar to Entity Framework, you create POJOs and annotate their fields to provide directives to the JPA provider about how to handle persistence.

其中有这里的教程不错,并且我鼓励您使用基于方面的方法查看 Spring Roo 手动管理大量簿记.

There's a decent tutorial here, and I encourage you to look at Spring Roo with its aspect-based approach which frees you from having to manage lots of the bookkeeping by hand.

这篇关于使用Hibernate进行代码优先处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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