@Entity with JSF,persist“hello world”与JPA [英] @Entity with JSF, persist "hello world" with JPA

查看:154
本文介绍了@Entity with JSF,persist“hello world”与JPA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Oracle 非常好地描述了如何使@Entity 。然而,对我来说,如何实际添加/删除表格并不是很清楚。我也喜欢玫瑰印度说明,但只是想澄清一般对于具有CDI的JSF JEE6应用程序,我基本上只需创建一个@Entity类,实例化@Named bean中的一些实例,并写入(CRUD操作)从bean到MySQL数据库的EntityManager?我可以使用Glassfish附带的默认JPA?



只是想在开始之前澄清一般想法。

解决方案

一般来说,您至少有两个选项:


  1. 创建数据库表和引用,然后根据数据库表构建实体类(现代IDE提供用于从db表自动生成实体类的工具)


  2. 手动编写实体类,并从这些类创建数据库。 JPA提供商通常通过在 persistence.xml 中设置一个特殊参数来允许这一点。对于Eclipselink:






 < property name =eclipselink.ddl-generationvalue =drop-and-create-tables/> 

删除所有现有的表,并从您的实体类创建新的表(在开发期间特别有用),而

 < property name =eclipselink.ddl-generationvalue =create-tables/ > 

只会在没有现有的情况下创建一个新表。


我可以使用Glassfish附带的默认JPA?



$ b $是的,对于基于规范的功能。


Oracle describes very well how to make an @Entity. However, it's not strictly clear to me how to actually add/drop tables. I also like the rose india explanation, but just want to clarify the general idea.

For a JSF JEE6 app with CDI, I can basically just create an @Entity class, instantiate some instances in the @Named bean, and write (CRUD operations) to the MySQL database with an EntityManager from the bean? I can just use default JPA which comes with Glassfish?

Just want to clarify the general idea before I get started.

解决方案

In general you have at least two options:

  1. Create your database tables and references, then build your entity classes based on the database tables (modern IDEs provide tools for automatic generation of entity classes from db tables)

  2. Write your entity class manually and create the database from these classes. JPA providers normally allow this by setting a special parameter in the persistence.xml , e.g. for Eclipselink:

<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>

drops all existing tables and creates new ones from your entity classes (especially useful during development), while

<property name="eclipselink.ddl-generation" value="create-tables"/>

will only create a new table if there is no existing.

I can just use default JPA which comes with Glassfish?

Yes, for the functionality that is based on the specification.

这篇关于@Entity with JSF,persist“hello world”与JPA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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