@Entity with JSF, persist “hello world” with JPA

人走茶凉 提交于 2019-12-12 01:52:28

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/10097504/entity-with-jsf-persist-hello-world-with-jpa

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!