eclipselink不会从带注释的JPA类生成表 [英] eclipselink does not generate tables from annotated JPA classes
问题描述
我的IDE是eclipse -Helios,我正在使用mojarra jsf,mysql,eclipselink for jpa。
My IDE is eclipse -Helios and I am using mojarra jsf, mysql, eclipselink for jpa.
在我的项目中,如果我在mysql中手动创建表,我可以在JPA详细信息视图中看到这些表。如果我不创建任何表,eclipse IDE会显示错误,Tabletrainingsession无法解决。
In my project, if I create the tables manually in mysql, I can see those tables in the "JPA Details" view. And if I don't create any table, the eclipse IDE shows an error, "Table "trainingsession" cannot be resolved".
我不确定是什么问题。 JPA何时会创建这些表?如何 ?
我的persistence.xml如下,
I am not sure what's wrong. When would JPA create these tables ? and how ? my persistence.xml is as follows,
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="wompower2" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>trainer</jta-data-source>
<class>com.jsfcompref.trainer.entity.User</class>
<class>com.jsfcompref.trainer.entity.TrainingSession</class>
<class>com.jsfcompref.trainer.entity.Event</class>
<class>com.jsfcompref.trainer.entity.AbstractEntity</class>
<validation-mode>NONE</validation-mode>
<properties>
<property name="eclipselink.target-database" value="MySQL"/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="both"/>
<property name="eclipselink.application-location" value="C:\wompower2\DDL"/>
<property name="eclipselink.create-ddl-jdbc-file-name" value="create.sql"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/demo"></property>
<property name="javax.persistence.jdbc.user" value="user"></property>
<property name="javax.persistence.jdbc.password" value="pwd"></property>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"></property>
</properties>
</persistence-unit>
</persistence>
谢谢你,
Arindam。
Thank you, Arindam.
推荐答案
GlassFish读取属性 eclipselink.ddl-generation
以决定它是否将使用自己的表生成功能 - java2db。这仅适用于部署期间,如果目标是DAS。
GlassFish reads the property eclipselink.ddl-generation
to decide whether it will use its own table generation functionality -- java2db. This only works during deployment and if the target is the DAS.
eclipselink.ddl-generation.output-的值无关紧要模式
你给,如果要使用java2db(以便它可以运行脚本),GlassFish会将其设置为sql-script,如果禁用,则将其设置为none。请参阅glassfish3 / persistence / jpa-connector / src / main / java / org / glassfish / persistence / jpa / PersistenceUnitLoader.java。
It doesn't matter the value of eclipselink.ddl-generation.output-mode
you give, GlassFish will set it to "sql-script" if java2db is to be used (so that it can then run the scripts) or "none" if it is disabled. See glassfish3/persistence/jpa-connector/src/main/java/org/glassfish/persistence/jpa/PersistenceUnitLoader.java.
这篇关于eclipselink不会从带注释的JPA类生成表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!