|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
How can I generate tables from entities?Hello,
since a few days I keep trying to generate SQL tables with EclipseLink and Dali (JavaSE). I made the following experiment: - using SQLExplorer I created an SQL table "employee" in database "test" - set up a JPA project "Employee_1" - successfully generated the entity "employee" from the above table with the JPA tools - again with SQLExplorer, dropped the table employee from the database - unsuccessfully tried to re-generate this table from the entity 1. Software configuration: eclipse-jee-ganymede-SR2-win32 eclipselink-2.0.0.v20090604-r4409 wtp-S-3.1RC3-20090602055316 MySQL 5.1 mysql-connector-java-5.1.7 2. The configuration of the JPA project: projekt name: Employee_1 target runtime: <None> configuration: Employee_1_Facets, containing: - Java 6.0 - Java Persistence 1.0 - Utility Module - Platform: EclpiseLink - Connection: MySQL-2, via MySQL JDBC Driver with the following properties: - Database: test - URL: jdbc:mysql://localhost:3306/ - User name: <user name> - Password: <password> [x] Save password When testing this connection the ping was successful. - implementation library: ECLIPSELINK_USER_LIB, containing: - eclipselink.jar - javax.persistence_1.0.0v200905011740.jar - javax.persistence_2.0_preview.jar - Persistent class management: Discover annotated classes automatically [x] Create orm.xml 3. persistence.xml: <?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence""http://www.w3.org/2001/XMLSchema-instance"http://java.sun.com/xml/ns/persistencehttp://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> <persistence-unit name="Employee_1" transaction-type="RESOURCE_LOCAL"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <properties> <property name="eclipselink.jdbc.url" value="jdbc:mysql://localhost:3306/"/> <property name="eclipselink.jdbc.user" value= <user name> /> <property name="eclipselink.jdbc.password" value= <password> /> <property name="eclipselink.jdbc.driver" value="com.mysql.jdbc.Driver"/> <property name="eclipselink.ddl-generation" value="create-tables"/> <property name="eclipselink.ddl-generation.output-mode" value="both"/> <property name="eclipselink.application-location" value= <location> /> </properties> </persistence-unit> </persistence> 4. Project directory tree after generating entity class "employee" from the respective table: Employee_1 | .classpath | .project | +---.settings | org.eclipse.jdt.core.prefs | org.eclipse.jpt.core.prefs | org.eclipse.jst.common.project.facet.core.prefs | org.eclipse.wst.common.component | org.eclipse.wst.common.project.facet.core.xml | +---build | +---classes | +---employee1 | | Employee.class | | | +---META-INF | MANIFEST.MF | orm.xml | persistence.xml +---src +---employee1 | Employee.java | +---META-INF MANIFEST.MF orm.xml persistence.xml 5. Trying to generate table "employee" gives the following error message: Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named Employee_1 at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89) at org.eclipse.jpt.eclipselink.core.ddlgen.Main.execute(Main.java:77) at org.eclipse.jpt.eclipselink.core.ddlgen.Main.main(Main.java:65) although I named a persistence provider in my persistence.xml which is contained in eclipselink.jar which itself is included in my user library ECLIPSELINK_USER_LIB. 6. Next, I imported this project into a newly installed workspace with a shorter pathname without any spaces ("C:\JPA"). Now, in persistence.xml the following line is added: <class>employee1.Employee</class> When I try again to generate the table, I get this error message: [EL Finest]: 2009-06-08 11:23:11.296--ServerSession(22522451)--Thread(Thread[main,5,main])--property=eclipselink.logging.timestamp; value=false [EL Finest]: ServerSession(22522451)--Thread(Thread[main,5,main])--property=eclipselink.logging.thread; value=false [EL Finest]: ServerSession(22522451)--property=eclipselink.logging.session; value=false [EL Finest]: property=eclipselink.logging.exceptions; value=true [EL Finest]: Begin predeploying Persistence Unit Employee_1; state Initial; factoryCount 0 [EL Info]: property eclipselink.jdbc.user is deprecated, property javax.persistence.jdbc.user should be used instead. [EL Info]: property eclipselink.jdbc.driver is deprecated, property javax.persistence.jdbc.driver should be used instead. [EL Info]: property eclipselink.jdbc.url is deprecated, property javax.persistence.jdbc.url should be used instead. [EL Info]: property eclipselink.jdbc.password is deprecated, property javax.persistence.jdbc.password should be used instead. [EL Finest]: property=eclipselink.weaving; value=false [EL Finest]: property=eclipselink.orm.throw.exceptions; value=true [EL Finer]: Searching for default mapping file in file:/C:/JPA/Employee_1/build/classes/ [EL Finer]: Found a default mapping file at file:/C:/JPA/Employee_1/build/classes/META-INF/orm.xml for root URL file:/C:/JPA/Employee_1/build/classes/ [EL Finer]: Searching for default mapping file in file:/C:/JPA/Employee_1/build/classes/ [EL Config]: The access type for the persistent class [class employee1.Employee] is set to [FIELD]. [EL Config]: The alias name for the entity class [class employee1.Employee] is being defaulted to: Employee. Exception in thread "main" Local Exception Stack: Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.0.0.v20090604-r4409): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader@11b86e7 Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.0.0.v20090604-r4409): org.eclipse.persistence.exceptions.EntityManagerSetupException Exception Description: Predeployment of PersistenceUnit [Employee_1] failed. Internal Exception: java.lang.SecurityException: class "javax.persistence.ElementCollection"'s signer information does not match signer information of other classes in the same package at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:121) at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:133) at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:67) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83) at org.eclipse.jpt.eclipselink.core.ddlgen.Main.execute(Main.java:77) at org.eclipse.jpt.eclipselink.core.ddlgen.Main.main(Main.java:65) Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.0.0.v20090604-r4409): org.eclipse.persistence.exceptions.EntityManagerSetupException Exception Description: Predeployment of PersistenceUnit [Employee_1] failed. Internal Exception: java.lang.SecurityException: class "javax.persistence.ElementCollection"'s signer information does not match signer information of other classes in the same package at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:879) at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.callPredeploy(JPAInitializer.java:110) at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.initPersistenceUnits(JPAInitializer.java:159) at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.initialize(JPAInitializer.java:144) at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:105) ... 4 more Caused by: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.0.0.v20090604-r4409): org.eclipse.persistence.exceptions.EntityManagerSetupException Exception Description: Predeployment of PersistenceUnit [Employee_1] failed. Internal Exception: java.lang.SecurityException: class "javax.persistence.ElementCollection"'s signer information does not match signer information of other classes in the same package at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:210) ... 9 more Caused by: java.lang.SecurityException: class "javax.persistence.ElementCollection"'s signer information does not match signer information of other classes in the same package at java.lang.ClassLoader.checkCerts(Unknown Source) at java.lang.ClassLoader.preDefineClass(Unknown Source) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$000(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source) at org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataAnnotatedElement.isElementCollection(MetadataAnnotatedElement.java:345) at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.buildAccessor(ClassAccessor.java:424) at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.addAccessorFields(ClassAccessor.java:344) at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.addAccessors(ClassAccessor.java:317) at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.preProcess(EntityAccessor.java:600) at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processStage1(MetadataProject.java:1028) at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processORMMetadata(MetadataProcessor.java:451) at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:297) at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:839) ... 8 more 7. After a few seconds, my entity class file Employee.java exhibits the following errors: - Schema "null" cannot be resolved for table "Employee" - Column "personid" cannot be resolved - Column "name" cannot be resolved I hope, someone can help me to get the table generator working. best regards Gerhard xmlns:xsi= xsi:schemaLocation=" _______________________________________________ eclipselink-users mailing list eclipselink-users@... https://dev.eclipse.org/mailman/listinfo/eclipselink-users |
|
|
Re: How can I generate tables from entities?The signing issue was from an issue with making the persistence.jar signed, because EclipseLink ships JPA 2.0 classes in its own jar. You need to either use the unsigned version of the persistence.jar (one that used to be included in EclipseLink, or one from any other source), or replace your JPA 1.0 persistence.jar with the JPA 2.0 persistence.jar.
James Sutherland EclipseLink, TopLink Wiki: EclipseLink, TopLink Forums: TopLink, EclipseLink Book: Java Persistence |
|
|
Re: How can I generate tables from entities?From 20090609:1027 parallel
thread
---------------------------------------------------------------------------------------------- Gerhard, 1) For your first issue where there are deprecation warnings, check the following - are you using 2 or more persistence units in your persistence.xml? I have 2 persistence units in my persistence.xml - I changed all 2 x 4 = 8 properties to get rid of warnings during preprocessing of both persistence units. - otherwise verify that your orm.xml is not overriding properties. For example... http://wiki.eclipse.org/EclipseLink/Examples/JPA/Tomcat_Web_Tutorial#Direct_connection_.28RESOURCE_LOCAL.29_Persistence.xml >Before: <property name="eclipselink.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/> <property name="eclipselink.jdbc.url" value=jdbc:oracle:thin:@.../> <property name="eclipselink.jdbc.user" value="user"/> <property name="eclipselink.jdbc.password" value="pw"/> >generates [EL Info]: 2009-06-09 09:23:48.156--ServerSession(18680399)--Thread(Thread[main,5,main])--property eclipselink.jdbc.user is deprecated, property javax.persistence.jdbc.user should be used instead. [EL Info]: 2009-06-09 09:23:48.156--ServerSession(18680399)--Thread(Thread[main,5,main])--property eclipselink.jdbc.driver is deprecated, property javax.persistence.jdbc.driver should be used instead. [EL Info]: 2009-06-09 09:23:48.156--ServerSession(18680399)--Thread(Thread[main,5,main])--property eclipselink.jdbc.url is deprecated, property javax.persistence.jdbc.url should be used instead. [EL Info]: 2009-06-09 09:23:48.156--ServerSession(18680399)--Thread(Thread[main,5,main])--property eclipselink.jdbc.password is deprecated, property javax.persistence.jdbc.password should be used instead. >After a change to <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/> <property name="javax.persistence.jdbc.url" value=jdbc:oracle:thin:@.../> <property name="javax.persistence.jdbc.user" value="user"/> <property name="javax.persistence.jdbc.password" value="pw"/> >generates no more property warnings. 2) For your lack of DDL script output, check that you are using the following format. both drop-and-create-tables and create-tables will generate a "dropDDL.jdbc" file. The key is that you should use "eclipselink.application-location" and not the spec defined "javax.persistence.application-location" property yet. >The following <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> <property name="eclipselink.ddl-generation.output-mode" value="both"/> <property name="eclipselink.create-ddl-jdbc-file-name" value="ddl.txt"/> <property name="eclipselink.application-location" value="c:/opt"/> >generates dropDDL.jdbc ddl.txt (with create table DDL entries) 3) Table generator within a program? See the usage of the following class http://fisheye2.atlassian.com/browse/eclipselink/trunk/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/tools/schemaframework/TableDefinition.java by the class http://fisheye2.atlassian.com/browse/eclipselink/trunk/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/tools/schemaframework/TableCreator.java using the method call public void replaceTables(org.eclipse.persistence.sessions.DatabaseSession session) from for example http://fisheye2.atlassian.com/browse/eclipselink/trunk/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/metamodel/MetamodelTest.java Note: When you use table generation in this way outside of standard JPA properties and annotations - you will be using native API of EclipseLink. thank you /michael Gerhard Kratz wrote: Hello, Michael, James Sutherland wrote: The signing issue was from an issue with making the persistence.jar signed, because EclipseLink ships JPA 2.0 classes in its own jar. You need to either use the unsigned version of the persistence.jar (one that used to be included in EclipseLink, or one from any other source), or replace your JPA 1.0 persistence.jar with the JPA 2.0 persistence.jar. Gerhard Kratz wrote: _______________________________________________ eclipselink-users mailing list eclipselink-users@... https://dev.eclipse.org/mailman/listinfo/eclipselink-users |
|
|
Re: How can I generate tables from entities?thank you very much for your answers. Now, my user library contains the following Java archives: - eclipselink.jar - javax.persistence_2.0_preview.jar and the table generator works fine. Hm. 1. I have just one persistence unit which is declared in my persistence.xml; there is no other persistence unit declared in orm.xml. (see attachment) Could the property declarations in persistence.xml nonetheless be overridden somehow? These property declarations are all in the form you recommended. Unfortunately, I get the same property warnings as before. The message output I get shows the objected lines for the first time during predeploying and a second time in the beginning of deployment. Later during deployment, the correct property values are confirmed: [EL Finest]: property=javax.persistence.jdbc.user; value= /***user***/ [EL Finest]: property=javax.persistence.jdbc.password; value= /***password***/ [EL Finest]: property=javax.persistence.jdbc.driver; value=com.mysql.jdbc.Driver [EL Finest]: property=javax.persistence.jdbc.url; value=jdbc:mysql://localhost:3306/test Could the difference in behavior between our two runs of the same program be due to the fact that you have a server application, whereas my program is not deployed to a server? 2. As before, DDL statements are not written into a text file. I tried it with "C:/JPA" and with "C:\JPA" as values for the application location, and I completely searched my hard disk. 3. Thanks for the hints to the appropriate classes. best regards Gerhard Michael O'Brien schrieb:
-- Prof. Dr. Gerhard Kratz Fachhochschule Frankfurt am Main Fachbereich 2: Informatik und Ingenieurwissenschaften Nibelungenplatz 1 60318 Frankfurt am Main WWW: http://www.fh-frankfurt.de/~g_kratz http://bscw.fh-frankfurt.de <?xml version="1.0" encoding="UTF-8"?> <persistence version="1.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_1_0.xsd"> <persistence-unit name="Employee_1" transaction-type="RESOURCE_LOCAL"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <class>employee1.Employee</class> <properties> <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/test"/> <property name="javax.persistence.jdbc.user" value= /***user***/ /> <property name="javax.persistence.jdbc.password" value= /***password***/ /> <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> <property name="eclipselink.ddl-generation.output-mode" value="both"/> <property name="eclipselink.create-ddl-jdbc-file-name" value="ddl.txt"/> <property name="eclipselink.application-location" value="C:/JPA"/> </properties> </persistence-unit> </persistence> <?xml version="1.0" encoding="UTF-8"?> <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd" version="1.0"> </entity-mappings> _______________________________________________ eclipselink-users mailing list eclipselink-users@... https://dev.eclipse.org/mailman/listinfo/eclipselink-users |
|
|
Re: How can I generate tables from entities?
Gerhard,
Hi, some observations for... 1) The example DDL generation program I use that is in our SVN repository is a standalone SE JPA application outside of the EAR. Note that DDL generation will not function on databases when run from a JEE application server if the persistence unit is using JTA because the implicit auto-commit function during a drop or create table is not valid in an atomic container managed transaction - therefore use DDL generation only in SE apps. The package name [org.eclipse.persistence.example.jpa.server.common.ddlgen] is misleading - the main() run target is DDLGenerationClient.java For the property warning messages, to verify that your persistence.xml is being modified - try to "break" it first by removing a key property or using an invalid provider string - sometimes the bin directory does not match src changes (in Eclipse if the project | build automatically flag is unset) For example, I switched to using the EclipseLink 1.1.2 distribution jars where we only support the older property names and got an expected exception using the following classpath if I didn't revert to "eclipselink.jdbc" <classpathentry kind="src" path="src"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="var" path="ORACLE_JDBC_LIB"/> <classpathentry kind="lib" path="C:/_transfer/eclipselink-1.1.2.v20090606-r4436/eclipselink/jlib/eclipselink.jar"/> <classpathentry kind="lib" path="C:/_transfer/eclipselink-1.1.2.v20090606-r4436/eclipselink/jlib/jpa/javax.persistence_1.0.0.v200905011740.jar"/> <classpathentry kind="output" path="bin"/> Caused by: Exception [EclipseLink-4021] (Eclipse Persistence Services - 1.1.2.v20090606-r4436): org.eclipse.persistence.exceptions.DatabaseException Exception Description: Unable to acquire a connection from driver [null], user [null] and URL [null]. Verify that you have set the expected driver class and URL. Check your login, persistence.xml or sessions.xml resource. The jdbc.driver property should be set to a class that is compatible with your database platform Bottom line, you can ignore the deprecation warnings for now. 2) Lack of DDL generation files Experiment 1: If I leave out eclipselink.application-location, the ddl files will be written to the runtime directory - in my case this is to the project root in my Eclipse workspace <?xml version="1.0" encoding="UTF-8"?> <persistence version="1.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_1_0.xsd"> <persistence-unit name="dao.create.tables.oracle" transaction-type="RESOURCE_LOCAL"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <class>org.eclipse.persistence.example.jpa.server.business.Cell</class> <properties> <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/> <property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.oracle.OraclePlatform"/> <property name="javax.persistence.jdbc.url" value=jdbc:oracle:thin:@.../> <property name="javax.persistence.jdbc.user" value="user"/> <property name="javax.persistence.jdbc.password" value="password"/> <property name="eclipselink.logging.level" value="ALL"/> <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> <property name="eclipselink.ddl-generation.output-mode" value="both"/> <property name="eclipselink.create-ddl-jdbc-file-name" value="ddl.txt"/> <!-- property name="eclipselink.application-location" value="C:/opt"/--> </properties> </persistence-unit> </persistence> generates to the following instead of c:/opt C:\view_w342e\examples\org.eclipse.persistence.example.jpa.server.common.ddlgen>dir 2009-06-11 09:35 678 ddl.txt 2009-06-11 09:35 274 dropDDL.jdbc I also run fine with the following changes because of auto-detection <!--property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/--> <!--property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.oracle.OraclePlatform"/--> <property name="eclipselink.ddl-generation" value="create-tables"/> To assist you, I have included a zip of the SE JPA DDL generation project, the output files and the log on the root for your comparison. Differences are the fact that I am running off trunk projects from the Eclipse IDE and using an Oracle DB. We both are running EclipseLink 2.0 I will try on MySQL instead of Oracle and advise later. thank you /michael Gerhard Kratz wrote:
_______________________________________________ eclipselink-users mailing list eclipselink-users@... https://dev.eclipse.org/mailman/listinfo/eclipselink-users |
| Free embeddable forum powered by Nabble | Forum Help |