Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
771 views
in Technique[技术] by (71.8m points)

jakarta ee - eclipselink does not generate tables from annotated JPA classes

My IDE is eclipse -Helios and I am using mojarra jsf, mysql, eclipselink for jpa.

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".

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:wompower2DDL"/>
      <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>

Thank you, Arindam.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

First let me clarify that JPA is a standard spec for ORM and EclipseLink is one of the implementor of the spec (Hibernate is another example). The spec doesn't mandate the creation of the schema or tables though EclipseLink provides a mechanism to create the tables for you through configuration. Below are the two config properties controlling that

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

Go through this tutorial for more information (specifically 3.2 section)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...