Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Dali » Persistence and Java SE - Example
Persistence and Java SE - Example [message #434561] Thu, 23 August 2007 17:14 Go to next message
Steve Ray is currently offline Steve RayFriend
Messages: 31
Registered: July 2009
Member
Before Europa I had a persistence application using Java SE and the
available persistence tools ( Dali and TopLink) running. I had to use
many pre-release pieces to make it happen. Now that I have Europa, I am
trying to recreate my application from scratch. I'm running into problems
with the tools. Can someone give me a step by step example of how to use
the tools to create a SE persistance application? Thanks for your help.
Re: Persistence and Java SE - Example [message #434562 is a reply to message #434561] Thu, 23 August 2007 19:21 Go to previous messageGo to next message
Karen Butzke is currently offline Karen ButzkeFriend
Messages: 220
Registered: July 2009
Senior Member
The main Dali website has links to the 1.0 documentation, tutorials, and
several demos:
http://www.eclipse.org/webtools/dali/main.php

Do you have any specific problems you are running into?

Karen
Re: Persistence and Java SE - Example [message #434564 is a reply to message #434562] Thu, 23 August 2007 21:04 Go to previous messageGo to next message
Steve Ray is currently offline Steve RayFriend
Messages: 31
Registered: July 2009
Member
Here's the situation. I can't make Dali 1.0 do the same things as I did
with Dali .5. I did follow the tutorials and that's where I'm stuck.
Once I have my database specified in the XML - I'm not getting the wrapper
classes for the tables automagically generated for me. Here's the steps I
followed. I hope I'm just doing something not smart:


Eclipse Europa Full Install
JPA SE application

Steps:
Connect to MySQL server.
New JPA Project
Target Runtime: <None> There does not appear to be a way to select the
TopLink Essentials agent for creating SE applications.
Configuration: Utility JPA project with Java 5.0
<Next>
<Next>
Connection: mysql
JPA implementation: Use implementation libary
Persistent class management: Discover annotated classes automatically
Create orm.xml checked
<Finish>
Context Menu on Project: JPA Tools/Generate Entities
Select MySQL server
Synchronize Classes in persistence.xml CHECKED
Three tables CHECKED
<Finish>

Problem Occurred: Synchronizing classes
An internal error occurred during: "Synchronizing classes".
java.lang.NullPointerException
<OK>

Wrapper classes generated
No information placed in persistence.xml
No information placed in orm.xml

Added toplink-essentials.jar to Java Build Path/Libraries

Since persistence.xml content wasn't generated.
Tried copying an existing file over. No errors but also no change to the
file.

Tried copying the contents from the predefined file to the new projects
persistence.xml file:
An error has occurred. See error log for more details.
Index out of bounds
<OK>

The generated persistence.xml file has the following contents which I seem
unable to modify manually:
<?xml version="1.0" encoding="UTF-8"?>

Context Menu on persistence.xml: JPA Tools/Synchronize Classes
Problem Occurred: Synchronizing classes
An internal error occurred during: "Synchronizing classes".
java.lang.NullPointerException
<OK>

This is as far as I can get on this particular test application. Without
persistence.xml I can't create an EntityManagerFactory.
Re: Persistence and Java SE - Example [message #434565 is a reply to message #434564] Fri, 24 August 2007 12:20 Go to previous messageGo to next message
Mark Hoffmann is currently offline Mark HoffmannFriend
Messages: 113
Registered: July 2009
Location: Jena
Senior Member
I have had som similar problems with the persistence.xml. This is what
my peristence.xml looks like:
<?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="name">
<provider>
oracle.toplink.essentials.PersistenceProvider
</provider>
<class>
model.Country</class>
<properties>
<property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="toplink.jdbc.url"
value="jdbc:mysql://servername:3306/databasename"/>
<property name="toplink.jdbc.user" value="username"/>
<property name="toplink.jdbc.password" value="password"/>
<property name="toplink.logging.level" value="INFO"/>
<property name="toplink.target-database" value="MySQL4"/>
<!-- <property name="toplink.ddl-generation" value="create-tables"/>-->
</properties>
</persistence-unit>
</persistence>

Sometimes I didn't get a predefined persistence.xml with the wizard. So
I saved my persistence.xml and copy it into the project again. But this
problem is not reproducable on my configuration.

Mark
Re: Persistence and Java SE - Example [message #434566 is a reply to message #434565] Fri, 24 August 2007 13:30 Go to previous messageGo to next message
Steve Ray is currently offline Steve RayFriend
Messages: 31
Registered: July 2009
Member
Even when I copy my old persistence.xml, it still fails.
Re: Persistence and Java SE - Example [message #434567 is a reply to message #434564] Fri, 24 August 2007 14:13 Go to previous messageGo to next message
Karen Butzke is currently offline Karen ButzkeFriend
Messages: 220
Registered: July 2009
Senior Member
> Eclipse Europa Full Install
> JPA SE application

> Steps:
> Connect to MySQL server.
> New JPA Project
> Target Runtime: <None> There does not appear to be a way to select the
> TopLink Essentials agent for creating SE applications.
> Configuration: Utility JPA project with Java 5.0
> <Next>
> <Next>
> Connection: mysql
> JPA implementation: Use implementation libary
> Persistent class management: Discover annotated classes automatically

You need to choose 'Annotated classes must be listed in the
persistence.xml' in the JPA project wizard or on the JPA properties page
for a project that is already created. Then when you generate entities,
the persistence.xml file will be synchronized. There is something
confusing going on with these actions, I am going to investigate and will
most likely enter a bug. 'Discover annotated class automatically' means
that the java files do not need to be listed in the persistence.xml file.
If you want them listed for your runtime application, do not choose this
option.

> Create orm.xml checked
> <Finish>
> Context Menu on Project: JPA Tools/Generate Entities
> Select MySQL server
> Synchronize Classes in persistence.xml CHECKED
> Three tables CHECKED
> <Finish>

> Problem Occurred: Synchronizing classes
> An internal error occurred during: "Synchronizing classes".
> java.lang.NullPointerException
> <OK>

It sounds like your persistence.xml file was not created correctly when
the project was orginally created (bug 187370). Could you verify that it
is a valid persistence.xml after the jpa project wizard has completed?
Otherwise, could you post the entire stack trace from this NPE? You can
find it in the Error Log.

> Wrapper classes generated
> No information placed in persistence.xml
> No information placed in orm.xml

We do not update the orm.xml file on entity generation, it only creates
java files. You do not need the orm.xml file unless you want to create
your entities in xml instead of java or if you want to override your java
entities in xml. You can also use the orm.xml file for persistence unit
defaults.

I hope this helps some, if you are still experiencing problems, please
post the fully stack traces.

Karen
Re: Persistence and Java SE - Example [message #434568 is a reply to message #434565] Fri, 24 August 2007 14:14 Go to previous messageGo to next message
Karen Butzke is currently offline Karen ButzkeFriend
Messages: 220
Registered: July 2009
Senior Member
The persistence.xml file is sometimes not created correctly, this is
documented in bug 187370.

Karen
Re: Persistence and Java SE - Example [message #434569 is a reply to message #434566] Fri, 24 August 2007 14:15 Go to previous messageGo to next message
Karen Butzke is currently offline Karen ButzkeFriend
Messages: 220
Registered: July 2009
Senior Member
It sounds like things might be in a bad state at this point, have you
tried restarting Eclipse after making the persistence.xml a valid xml file?

Karen
Re: Persistence and Java SE - Example [message #434570 is a reply to message #434567] Wed, 29 August 2007 13:55 Go to previous messageGo to next message
Steve Ray is currently offline Steve RayFriend
Messages: 31
Registered: July 2009
Member
I got farther but still have problems: See below:

Trying to create a new SE, JPA project in the Europa release of Eclipse.
Using glassfish, toplink-essentials and MySQL.

NOTE:
************************************************************ *********************************************************
Projects that were created with Eclipse 3.2 and Dali 0.5 still work.
Java Projects created with Europa that manually add persistence work.
Running into issues with a new JPA project using JPA wizards in Europa.

New JPA Project
************************************************************ *********************************************************
Name: JPA_2
Project Contents: Use default [checked]
Target Runtime: <None>
Configurations: Utility JPA project with Java 6.0
EAR Membership: Add project to an EAR [unchecked]
<Next>
<Next>
Platform: Generic
Connection: mysql
SQL Model-JDBC Connection
Name: mysql
Description:
Auto-connect when the wizards finished or when Data Source Explorer
opens. [checked]
<NEXT>

Driver: MySQL JDBC Driver 5.0.6
Database: javashare
URL: jdbc:mysql://saturna.ca.boeing.com:3306/javashare
UserName: JavaFriends
Password: ********
Save Password [checked]
<Test Connection> Ping succeeded!
<Next>
<Finish>

Platform: Generic
Connection: mysql
JPA implementation: Use implementation library: <None>
Persistent class management: Annotated classes must be listed in
persistence.xml
Create orm.xml [unchecked]
<Finish>

Package Explorer
JPA_2
Context Menu: JPA Tools/Generate Entities...
Connection: MySQL 5.0.6
Schema: javashare
<Next>
Source folder: JPA_2/src
Package: (default) // For sample project only.
Synchronize Classes in persistence.xml [checked]
<Select All> // Three simple tables.
<Finish>

Added a simple class, JPA_2, to contain "main" which retrieves the first
record and displays its fields to the console.
The import javax.persistence cannot be resolved.
Package Explorer
JPA_2
Context Menu: Properties
Tree: Java Build Path
Tab: Libraries
<Add External JARs...>
mysql-connector-java-5.0.6-bin.jar
<Open>
<Add External JARs...>
toplink-essentials.jar
<Open>
<OK>

Menu: Run/Open Run Dialog...
New Launch Configuration
Tab: Main
Name: JPA_2
Project: JPA_2
Main class: JPA_2
Tab: Arguments
Program arguments:
VM arguments: -javaagent:"C:\Documents and Settings\rt954c\My
Documents\workspace\glassfish-persistence\toplink-essentials -agent.jar "
<Apply>
<Run>

Runtime Errors:
************************************************************ *********************************************************
[TopLink Info]: 2007.08.28 09:07:22.964--ServerSession(6889270)--TopLink,
version: Oracle TopLink Essentials - 2.0 (Build b48-beta3 (05/23/2007))
Exception in thread "main" Local Exception Stack:
Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0 (Build b48-beta3
(05/23/2007))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: [Microsoft][ODBC Driver
Manager] Data source name not found and no default driver specified
Error Code: 0
at
oracle.toplink.essentials.exceptions.DatabaseException.sqlEx ception(DatabaseException.java:305)
at
oracle.toplink.essentials.sessions.DefaultConnector.connect( DefaultConnector.java:102)
at
oracle.toplink.essentials.sessions.DatasourceLogin.connectTo Datasource(DatasourceLogin.java:185)
at
oracle.toplink.essentials.internal.sessions.DatabaseSessionI mpl.loginAndDetectDatasource(DatabaseSessionImpl.java:552)
at
oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvi der.login(EntityManagerFactoryProvider.java:221)
at
oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSet upImpl.deploy(EntityManagerSetupImpl.java:227)
at
oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManag erFactoryImpl.getServerSession(EntityManagerFactoryImpl.java :93)
at
oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManag erFactoryImpl.createEntityManagerImpl(EntityManagerFactoryIm pl.java:126)
at
oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManag erFactoryImpl.createEntityManagerImpl(EntityManagerFactoryIm pl.java:120)
at
oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerFac toryImpl.createEntityManager(EntityManagerFactoryImpl.java:9 1)
at JPA_2.main(JPA_2.java:24)
Caused by: java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data
source name not found and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at
oracle.toplink.essentials.sessions.DefaultConnector.connect( DefaultConnector.java:100)
... 9 more

Manually build persistence.xml
************************************************************ *********************************************************
<?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="JPA_2">
<provider>
oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvi der
</provider>
<class>TInterestLinks</class>
<class>TInterests</class>
<class>TMembers</class>
<properties>
<property name="toplink.jdbc.url"
value="jdbc:mysql://saturna.ca.boeing.com/javashare" />
<property name="toplink.jdbc.driver"
value="com.mysql.jdbc.Driver" />
<property name="toplink.jdbc.user" value="JavaFriends" />
<property name="toplink.jdbc.password" value="ShareTheFun" />
</properties>
</persistence-unit>
</persistence>

Runtime Errors:
************************************************************ *********************************************************
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(Un known
Source)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(U nknown
Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izerAgent.initializeFromAgent(JavaSECMPInitializerAgent.java :69)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izerAgent.premain(JavaSECMPInitializerAgent.java:62)
... 6 more
Caused by: javax.persistence.PersistenceException: Exception
[TOPLINK-28018] (Oracle TopLink Essentials - 2.0 (Build b48-beta3
(05/23/2007))):
oracle.toplink.essentials.exceptions.EntityManagerSetupExcep tion
Exception Description: predeploy for PersistenceUnit [JPA_2] failed.
Internal Exception: Exception [TOPLINK-7155] (Oracle TopLink Essentials -
2.0 (Build b48-beta3 (05/23/2007))):
oracle.toplink.essentials.exceptions.ValidationException
Exception Description: The type [class java.lang.Object] for the attribute
[activeSubTeam] on the entity class [class TInterests] is not a valid type
for a serialized mapping. The attribute type must implement the
Serializable interface.
at
oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSet upImpl.predeploy(EntityManagerSetupImpl.java:630)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izer.callPredeploy(JavaSECMPInitializer.java:171)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izer.initPersistenceUnits(JavaSECMPInitializer.java:251)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izer.initialize(JavaSECMPInitializer.java:267)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izer.initializeFromAgent(JavaSECMPInitializer.java:284)
... 12 more
Caused by: Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.0
(Build b48-beta3 (05/23/2007))):
oracle.toplink.essentials.exceptions.EntityManagerSetupExcep tion
Exception Description: predeploy for PersistenceUnit [JPA_2] failed.
Internal Exception: Exception [TOPLINK-7155] (Oracle TopLink Essentials -
2.0 (Build b48-beta3 (05/23/2007))):
oracle.toplink.essentials.exceptions.ValidationException
Exception Description: The type [class java.lang.Object] for the attribute
[activeSubTeam] on the entity class [class TInterests] is not a valid type
for a serialized mapping. The attribute type must implement the
Serializable interface.
at
oracle.toplink.essentials.exceptions.EntityManagerSetupExcep tion.predeployFailed(EntityManagerSetupException.java:228)
... 17 more
Caused by: Exception [TOPLINK-7155] (Oracle TopLink Essentials - 2.0
(Build b48-beta3 (05/23/2007))):
oracle.toplink.essentials.exceptions.ValidationException
Exception Description: The type [class java.lang.Object] for the attribute
[activeSubTeam] on the entity class [class TInterests] is not a valid type
for a serialized mapping. The attribute type must implement the
Serializable interface.
at
oracle.toplink.essentials.exceptions.ValidationException.inv alidTypeForSerializedAttribute(ValidationException.java:963)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.Metadat aValidator.throwInvalidTypeForSerializedAttribute(MetadataVa lidator.java:254)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.DirectAccessor.processSerialized(DirectAccessor.java:302)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.DirectAccessor.processJPAConverters(DirectAccessor.java:2 49)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.DirectAccessor.processMappingConverter(DirectAccessor.jav a:287)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.BasicAccessor.processDirectToFieldMapping(BasicAccessor.j ava:188)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.BasicAccessor.process(BasicAccessor.java:160)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.ClassAccessor.processAccessor(ClassAccessor.java:528)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.ClassAccessor.processAccessorFields(ClassAccessor.java:54 1)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.ClassAccessor.processAccessors(ClassAccessor.java:567)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.ClassAccessor.process(ClassAccessor.java:498)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.Metadat aProcessor.processAnnotations(MetadataProcessor.java:240)
at
oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUn itProcessor.processORMetadata(PersistenceUnitProcessor.java: 369)
at
oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSet upImpl.predeploy(EntityManagerSetupImpl.java:599)
... 16 more
FATAL ERROR in native method: processing of -javaagent failed
Exception in thread "main"

Syntax Errors show up after trying to run
************************************************************ *********************************************************
Schema "JavaFriends" cannot be resolved for table "t_Members" ...
Schema "JavaFriends" cannot be resolved for table "t_Interest_Links" ...
Schema "JavaFriends" cannot be resolved for table "t_Interests" ...

The only place "JavaFriends" added to the project is as the User property
when setting up the mysql driver connection and the persistence.xml file.
The database schema in this case is "javashare"
Re: Persistence and Java SE - Example [message #434571 is a reply to message #434570] Wed, 29 August 2007 20:40 Go to previous messageGo to next message
Karen Butzke is currently offline Karen ButzkeFriend
Messages: 220
Registered: July 2009
Senior Member
> Manually build persistence.xml
>
************************************************************ *********************************************************
> <?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="JPA_2">
> <provider>
> oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvi der
> </provider>
> <class>TInterestLinks</class>
> <class>TInterests</class>
> <class>TMembers</class>
> <properties>
> <property name="toplink.jdbc.url"
> value="jdbc:mysql://saturna.ca.boeing.com/javashare" />
> <property name="toplink.jdbc.driver"
> value="com.mysql.jdbc.Driver" />
> <property name="toplink.jdbc.user" value="JavaFriends" />
> <property name="toplink.jdbc.password" value="ShareTheFun" />
> </properties>
> </persistence-unit>
> </persistence>

Dali does not support editing the properties in the persistence.xml.
These are specific to TopLink Essentials (or whatever persistence
provider). You will have to edit the persistence.xml manually to include
the provider and the properties.

> Runtime Errors:

Could you post the TInterests class so I can see what might be mapped
incorrectly?


> Schema "JavaFriends" cannot be resolved for table "t_Members" ...
> Schema "JavaFriends" cannot be resolved for table "t_Interest_Links" ...
> Schema "JavaFriends" cannot be resolved for table "t_Interests" ...

> The only place "JavaFriends" added to the project is as the User property
> when setting up the mysql driver connection and the persistence.xml file.
> The database schema in this case is "javashare"

Dali is using the user name "JavaFriends" as the default schema. To use
the correct schema, you either need to specify it everywhere you specify a
table or edit the orm.xml to include a persistence unit default schema of
"javashare". You can do that in the JPA Details Persistence Unit section.

<?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">
<persistence-unit-metadata>
<persistence-unit-defaults>
<schema>javashare</schema>
</persistence-unit-defaults>
</persistence-unit-metadata>
</entity-mappings>
Re: Persistence and Java SE - Example [message #434572 is a reply to message #434570] Thu, 30 August 2007 10:12 Go to previous messageGo to next message
Mark Hoffmann is currently offline Mark HoffmannFriend
Messages: 113
Registered: July 2009
Location: Jena
Senior Member
This is a multi-part message in MIME format.
--------------050901090004000001080402
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Hello,

I've succesfully created an SE Project:
1. create JPA project:

- Target runtime: none Configurations: Default Configurations -> NEXT
- NEXT
- Select you Connection
- I neither used Implementation from server-runtime nor an
implementation library (I added the jar later to the build-path)
- check "Annotated classes must be listed in persistence.xml"
- uncheck "Create orm.xml" -> FINISH

2. Now go to the project properties - Java Build Path - Libraries - add
external jars. Add toplink-essentials.jar and the
mysql-connector-java-5.x.x-bin.jar. Now press ok.

3. I attached you my persistence.xml. For SE project a took another provider

4. now i created the entities, a main class, db-structure

5. creating entites from a existing schema works also well for me.

I hope this will help you

Mark



--------------050901090004000001080402
Content-Type: text/xml;
name="persistence.xml"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="persistence.xml"

<?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="JPA2" transaction-type="RESOURCE_LOCAL">
<provider>
oracle.toplink.essentials.PersistenceProvider
</provider>
<class>
test.entities.Contact</class>
<class>
test.entities.Meeting</class>
<properties>
<property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="toplink.jdbc.url" value="jdbc:mysql://myserver:3306/test"/>
<property name="toplink.jdbc.user" value="myuser"/>
<property name="toplink.jdbc.password" value="mypassword"/>
<property name="toplink.logging.level" value="INFO"/>
<property name="toplink.target-database" value="MySQL4"/>
<!-- <property name="toplink.ddl-generation" value="create-tables"/>-->
</properties>
</persistence-unit>
</persistence>

--------------050901090004000001080402
Content-Type: text/plain;
name="Contact.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="Contact.java"

package test.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.ManyToMany;
import javax.persistence.JoinTable;
import javax.persistence.JoinColumn;

@Entity
@Table(schema="test", name = "contact")
public class Contact implements Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;

@Id
private int id = 0;

private String name = new String();

@ManyToMany
@JoinTable(name="contact_meeting", joinColumns = @JoinColumn(name="contact_id"), inverseJoinColumns = @JoinColumn(name="meeting_id"))
private Collection<Meeting> meetings = new ArrayList<Meeting>(1);

/**
* @return Liefert das Attribut id
*/
public int getId() {
return id;
}

/**
* @return Liefert das Attribut name
*/
public String getName() {
return name;
}

/**
* @return Liefert das Attribut meetings
*/
public Collection<Meeting> getMeetings() {
return meetings;
}

}

--------------050901090004000001080402
Content-Type: text/plain;
name="Main.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="Main.java"

package test.main;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import test.entities.Contact;
import test.entities.Meeting;

public class Main {

/**
* @param args
*/
public static void main(String[] args) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPA2");
/*
* EntityManager holen
*/
EntityManager em = emf.createEntityManager();

Contact c = em.find(Contact.class, 1);
System.out.println("Name: " + c.getName());
for (Meeting m : c.getMeetings()) {
System.out.println("Meeting: " + m.getDescription());
}
}

}

--------------050901090004000001080402
Content-Type: text/plain;
name="Meeting.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="Meeting.java"

package test.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Id;
import javax.persistence.Column;
import javax.persistence.ManyToMany;

@Entity
@Table(schema="test", name = "meeting")
public class Meeting implements Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;

@Id
@Column(table="meeting", name = "id")
private int id = 0;

private String description = new String();

@ManyToMany(targetEntity=test.entities.Contact.class, mappedBy = "meetings")
private Collection<Contact> attendees = new ArrayList<Contact>(1);

/**
* @return Liefert das Attribut id
*/
public int getId() {
return id;
}

/**
* @return Liefert das Attribut description
*/
public String getDescription() {
return description;
}

/**
* @return Liefert das Attribut attendees
*/
public Collection<Contact> getAttendees() {
return attendees;
}

}

--------------050901090004000001080402
Content-Type: text/plain;
name="script.sql.ddl"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="script.sql.ddl"

Q1JFQVRFIFRBQkxFIGNvbnRhY3QgKA0KCWlkIElOVCBERUZBVUxUICcnIE5P VCBOVUxMLA0K
CW5hbWUgVkFSQ0hBUigyNTUpIERFRkFVTFQgJycgTk9UIE5VTEwsDQoJUFJJ TUFSWSBLRVkg
KGlkKQ0KKSBFTkdJTkU9TXlJU0FNOw0KDQpDUkVBVEUgVEFCTEUgY29udGFj dF9tZWV0aW5n
ICgNCgljb250YWN0X2lkIElOVCBERUZBVUxUICcnIE5PVCBOVUxMLA0KCW1l ZXRpbmdfaWQg
SU5UIERFRkFVTFQgJycgTk9UIE5VTEwNCikgRU5HSU5FPU15SVNBTTsNCg0K Q1JFQVRFIFRB
QkxFIG1lZXRpbmcgKA0KCWlkIElOVCBERUZBVUxUICcnIE5PVCBOVUxMLA0K CWRlc2NyaXB0
aW9uIFZBUkNIQVIoMjU1KSBERUZBVUxUICcnIE5PVCBOVUxMLA0KCVBSSU1B UlkgS0VZIChp
ZCkNCikgRU5HSU5FPU15SVNBTTs=
--------------050901090004000001080402--
Re: Persistence and Java SE - Example [message #434573 is a reply to message #434571] Thu, 30 August 2007 13:25 Go to previous messageGo to next message
Steve Ray is currently offline Steve RayFriend
Messages: 31
Registered: July 2009
Member
OK, no longer seeing syntax error when I try and run, however, still
getting runtime errors. Looks like a problem with persistence XML. Since
persistence.xml has to be created manually, is there any documentation on
how to do so?


java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(Un known
Source)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(U nknown
Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izerAgent.initializeFromAgent(JavaSECMPInitializerAgent.java :69)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izerAgent.premain(JavaSECMPInitializerAgent.java:62)
... 6 more
Caused by: Exception [TOPLINK-30004] (Oracle TopLink Essentials - 2.0
(Build b48-beta3 (05/23/2007))):
oracle.toplink.essentials.exceptions.PersistenceUnitLoadingE xception
Exception Description: An exception was thrown while processing
persistence.xml from URL:
file:/C:/Documents%20and%20Settings/rt954c/My%20Documents/wo rkspace/JPA_2/build/classes/
Internal Exception:
(1. cvc-complex-type.2.4.a: Invalid content was found starting with
element 'provider'. One of
'{"http://java.sun.com/xml/ns/persistence":mapping-file,
"http://java.sun.com/xml/ns/persistence":jar-file,
"http://java.sun.com/xml/ns/persistence":class,
"http://java.sun.com/xml/ns/persistence":exclude-unlisted-classes,
"http://java.sun.com/xml/ns/persistence":properties}' is expected.)
at
oracle.toplink.essentials.exceptions.PersistenceUnitLoadingE xception.exceptionProcessingPersistenceXML(PersistenceUnitLo adingException.java:134)
at
oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUn itProcessor.processPersistenceXML(PersistenceUnitProcessor.j ava:161)
at
oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUn itProcessor.processPersistenceArchive(PersistenceUnitProcess or.java:99)
at
oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUn itProcessor.getPersistenceUnits(PersistenceUnitProcessor.jav a:89)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izer.initPersistenceUnits(JavaSECMPInitializer.java:248)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izer.initialize(JavaSECMPInitializer.java:267)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izer.initializeFromAgent(JavaSECMPInitializer.java:284)
... 12 more
Caused by:
(1. cvc-complex-type.2.4.a: Invalid content was found starting with
element 'provider'. One of
'{"http://java.sun.com/xml/ns/persistence":mapping-file,
"http://java.sun.com/xml/ns/persistence":jar-file,
"http://java.sun.com/xml/ns/persistence":class,
"http://java.sun.com/xml/ns/persistence":exclude-unlisted-classes,
"http://java.sun.com/xml/ns/persistence":properties}' is expected.)
at
oracle.toplink.essentials.internal.ejb.cmp3.xml.parser.XMLEx ceptionHandler.error(XMLExceptionHandler.java:52)
at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper. error(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.rep ortError(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.rep ortError(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidato r$XSIErrorReporter.reportError(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidato r.reportSchemaError(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidato r.handleStartElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidato r.startElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScanner Impl.scanStartElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl$FragmentContentDriver.next(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl.next(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScanner Impl.next(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(U nknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSA XParser.parse(Unknown
Source)
at
oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUn itProcessor.processPersistenceXML(PersistenceUnitProcessor.j ava:151)
... 17 more
FATAL ERROR in native method: processing of -javaagent failed
Exception in thread "main"
Here's TInterests.java

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="t_Interests")
public class TInterests implements Serializable {
@Id
@Column(name="interest_id")
private int interestId;

@Column(name="active_sub_team")
private Object activeSubTeam;

private String name;

private String description;

private static final long serialVersionUID = 1L;

public TInterests() {
super();
}

public int getInterestId() {
return this.interestId;
}

public void setInterestId(int interestId) {
this.interestId = interestId;
}

public Object getActiveSubTeam() {
return this.activeSubTeam;
}

public void setActiveSubTeam(Object activeSubTeam) {
this.activeSubTeam = activeSubTeam;
}

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return this.description;
}

public void setDescription(String description) {
this.description = description;
}

}


And persistence.xml

<?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="JPA_2">
<mapping-file>META-INF/orm.xml</mapping-file>

<provider> oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvi der </provider>
<class>TInterestLinks</class>
<class>TInterests</class>
<class>TMembers</class>
- <properties>
<property name="toplink.jdbc.url"
value="jdbc:mysql://saturna.ca.boeing.com/javashare" />
<property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="toplink.jdbc.user" value="JavaFriends" />
<property name="toplink.jdbc.password" value="ShareTheFun" />
</properties>
</persistence-unit>
</persistence>

And orm.xml:

<?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">
- <persistence-unit-metadata>
- <persistence-unit-defaults>
<schema>javashare</schema>
</persistence-unit-defaults>
</persistence-unit-metadata>
</entity-mappings>
Re: Persistence and Java SE - Example [message #434574 is a reply to message #434573] Thu, 30 August 2007 14:24 Go to previous messageGo to next message
Karen Butzke is currently offline Karen ButzkeFriend
Messages: 220
Registered: July 2009
Senior Member
If you edit the persistence.xml from within eclipse you should see the
same error. The element <provider> belongs before the <mapping-file
element>. Using eclipse you should be able to at least get schema
validation. TopLink Essentials documentation on the persistence.xml
properties they support is found at
http://www.oracle.com/technology/products/ias/toplink/JPA/es sentials/toplink-jpa-extensions.html
You can also look at the EJB 3.0 persistence spec.


The original runtime exception you were getting is because of the mapping
@Column(name="active_sub_team")
private Object activeSubTeam;

We generated type Object probably because the data type of active_sub_team
is something we don't know how to handle. You will have to change what we
generated since in JPA you cannot map Object as a direct mapping. The
error message was trying to say that Object was not Serializable which is
one way to map a type as a direct mapping.

Karen
Re: Persistence and Java SE - Example [message #434575 is a reply to message #434574] Thu, 30 August 2007 19:22 Go to previous messageGo to next message
Steve Ray is currently offline Steve RayFriend
Messages: 31
Registered: July 2009
Member
Finally. Thanks for your help. A couple of questions:

I have a table with a boolean in it:

Table t_Interests has a field, active_sub_team defined as a Boolean.

Dali 0.5 generated TInterest.java working the pre-Europa projects.
@Column(name="active_sub_team")
private short activeSubTeam;

Eclipse Europa, is different causing another exception.
@Column(name="active_sub_team")
private Object activeSubTeam;

Exceptions:
**********************************************************
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(Un known
Source)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(U nknown
Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izerAgent.initializeFromAgent(JavaSECMPInitializerAgent.java :69)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izerAgent.premain(JavaSECMPInitializerAgent.java:62)
... 6 more
Caused by: javax.persistence.PersistenceException: Exception
[TOPLINK-28018] (Oracle TopLink Essentials - 2.0 (Build b48-beta3
(05/23/2007))):
oracle.toplink.essentials.exceptions.EntityManagerSetupExcep tion
Exception Description: predeploy for PersistenceUnit [JPA_2] failed.
Internal Exception: Exception [TOPLINK-7155] (Oracle TopLink Essentials -
2.0 (Build b48-beta3 (05/23/2007))):
oracle.toplink.essentials.exceptions.ValidationException
Exception Description: The type [class java.lang.Object] for the attribute
[activeSubTeam] on the entity class [class TInterests] is not a valid type
for a serialized mapping. The attribute type must implement the
Serializable interface.
at
oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSet upImpl.predeploy(EntityManagerSetupImpl.java:630)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izer.callPredeploy(JavaSECMPInitializer.java:171)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izer.initPersistenceUnits(JavaSECMPInitializer.java:251)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izer.initialize(JavaSECMPInitializer.java:267)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izer.initializeFromAgent(JavaSECMPInitializer.java:284)
... 12 more
Caused by: Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.0
(Build b48-beta3 (05/23/2007))):
oracle.toplink.essentials.exceptions.EntityManagerSetupExcep tion
Exception Description: predeploy for PersistenceUnit [JPA_2] failed.
Internal Exception: Exception [TOPLINK-7155] (Oracle TopLink Essentials -
2.0 (Build b48-beta3 (05/23/2007))):
oracle.toplink.essentials.exceptions.ValidationException
Exception Description: The type [class java.lang.Object] for the attribute
[activeSubTeam] on the entity class [class TInterests] is not a valid type
for a serialized mapping. The attribute type must implement the
Serializable interface.
at
oracle.toplink.essentials.exceptions.EntityManagerSetupExcep tion.predeployFailed(EntityManagerSetupException.java:228)
... 17 more
Caused by: Exception [TOPLINK-7155] (Oracle TopLink Essentials - 2.0
(Build b48-beta3 (05/23/2007))):
oracle.toplink.essentials.exceptions.ValidationException
Exception Description: The type [class java.lang.Object] for the attribute
[activeSubTeam] on the entity class [class TInterests] is not a valid type
for a serialized mapping. The attribute type must implement the
Serializable interface.
at
oracle.toplink.essentials.exceptions.ValidationException.inv alidTypeForSerializedAttribute(ValidationException.java:963)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.Metadat aValidator.throwInvalidTypeForSerializedAttribute(MetadataVa lidator.java:254)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.DirectAccessor.processSerialized(DirectAccessor.java:302)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.DirectAccessor.processJPAConverters(DirectAccessor.java:2 49)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.DirectAccessor.processMappingConverter(DirectAccessor.jav a:287)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.BasicAccessor.processDirectToFieldMapping(BasicAccessor.j ava:188)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.BasicAccessor.process(BasicAccessor.java:160)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.ClassAccessor.processAccessor(ClassAccessor.java:528)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.ClassAccessor.processAccessorFields(ClassAccessor.java:54 1)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.ClassAccessor.processAccessors(ClassAccessor.java:567)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.ClassAccessor.process(ClassAccessor.java:498)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.Metadat aProcessor.processAnnotations(MetadataProcessor.java:240)
at
oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUn itProcessor.processORMetadata(PersistenceUnitProcessor.java: 369)
at
oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSet upImpl.predeploy(EntityManagerSetupImpl.java:599)
... 16 more
FATAL ERROR in native method: processing of -javaagent failed
Exception in thread "main"

Secondly:

In a project built with Dali 0.5, I had created a persistence.xml file
with two persistence-unit definitions. In Europa, it is flagging an error
about this. Does this mean that the schema has changed? Are we really
locked to a single DB for a persistence project or is there another
mechanism to achieve this? While the project I created was for
instructional purposes on how the same project could use identical
databases implemented in MySQL and Access, a real world application may
need to pull data from multiple sources. In fact I can think of a few
future projects that would work best with multiple distinct databases.

Fortunately, the Europa project with two persistence-unit definitions
still works and allows me to select the desired persistence-unit to use.
The createEntityManagerFactory also seems to be designed with this in mind.

EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPA_2");

If it didn't, then we shouldn't have to specify the persistence-unit name.

OK, I'm confused. According to
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd multiple
persistence-unit definitions are allowed.
<xsd:element name="persistence-unit" minOccurs="0" maxOccurs="unbounded">

Why am I getting an error then in my persistence.xml?

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

....
Severity and Description Path Resource Location Creation Time Id
Multiple persistence units defined JPA_2/src/META-INF persistence.xml line
2 1188499881616 27799
Re: Persistence and Java SE - Example [message #434576 is a reply to message #434575] Fri, 31 August 2007 14:51 Go to previous message
Karen Butzke is currently offline Karen ButzkeFriend
Messages: 220
Registered: July 2009
Senior Member
Steve Ray wrote:

> I have a table with a boolean in it:

> Table t_Interests has a field, active_sub_team defined as a Boolean.

> Dali 0.5 generated TInterest.java working the pre-Europa projects.
> @Column(name="active_sub_team")
> private short activeSubTeam;

> Eclipse Europa, is different causing another exception.
> @Column(name="active_sub_team")
> private Object activeSubTeam;

The major change to entity generation from .5 to 1.0 was the switch from
WTP's RDB to the DataTools project (DTP). This could be a bug in DTP's
mySQL support. For now you will just have to change the type of the
attribute after generation. Could you enter a bug against Dali for this
problem?

> Secondly:

> In a project built with Dali 0.5, I had created a persistence.xml file
> with two persistence-unit definitions. In Europa, it is flagging an error
> about this. Does this mean that the schema has changed? Are we really
> locked to a single DB for a persistence project or is there another
> mechanism to achieve this? While the project I created was for
> instructional purposes on how the same project could use identical
> databases implemented in MySQL and Access, a real world application may
> need to pull data from multiple sources. In fact I can think of a few
> future projects that would work best with multiple distinct databases.

> Why am I getting an error then in my persistence.xml?

We should make this a warning not an error and make it clear that *Dali*
doesn't support multiple persistence units. The JPA spec certainly does.
I agree that an error is too strong. Could you enter a bug to change this
from an error to a warning and make the message clearer?

We have an enhancement request (194833) open for supporting multiple
persistence units. The difficultly comes if the persistence units have
overlapping classes. The tooling doesn't know which context to support
for defaults and validation.

Thanks for reporting these issues.

Karen
Re: Persistence and Java SE - Example [message #605406 is a reply to message #434561] Thu, 23 August 2007 19:21 Go to previous message
Karen Butzke is currently offline Karen ButzkeFriend
Messages: 220
Registered: July 2009
Senior Member
The main Dali website has links to the 1.0 documentation, tutorials, and
several demos:
http://www.eclipse.org/webtools/dali/main.php

Do you have any specific problems you are running into?

Karen
Re: Persistence and Java SE - Example [message #605408 is a reply to message #434562] Thu, 23 August 2007 21:04 Go to previous message
Steve Ray is currently offline Steve RayFriend
Messages: 31
Registered: July 2009
Member
Here's the situation. I can't make Dali 1.0 do the same things as I did
with Dali .5. I did follow the tutorials and that's where I'm stuck.
Once I have my database specified in the XML - I'm not getting the wrapper
classes for the tables automagically generated for me. Here's the steps I
followed. I hope I'm just doing something not smart:


Eclipse Europa Full Install
JPA SE application

Steps:
Connect to MySQL server.
New JPA Project
Target Runtime: <None> There does not appear to be a way to select the
TopLink Essentials agent for creating SE applications.
Configuration: Utility JPA project with Java 5.0
<Next>
<Next>
Connection: mysql
JPA implementation: Use implementation libary
Persistent class management: Discover annotated classes automatically
Create orm.xml checked
<Finish>
Context Menu on Project: JPA Tools/Generate Entities
Select MySQL server
Synchronize Classes in persistence.xml CHECKED
Three tables CHECKED
<Finish>

Problem Occurred: Synchronizing classes
An internal error occurred during: "Synchronizing classes".
java.lang.NullPointerException
<OK>

Wrapper classes generated
No information placed in persistence.xml
No information placed in orm.xml

Added toplink-essentials.jar to Java Build Path/Libraries

Since persistence.xml content wasn't generated.
Tried copying an existing file over. No errors but also no change to the
file.

Tried copying the contents from the predefined file to the new projects
persistence.xml file:
An error has occurred. See error log for more details.
Index out of bounds
<OK>

The generated persistence.xml file has the following contents which I seem
unable to modify manually:
<?xml version="1.0" encoding="UTF-8"?>

Context Menu on persistence.xml: JPA Tools/Synchronize Classes
Problem Occurred: Synchronizing classes
An internal error occurred during: "Synchronizing classes".
java.lang.NullPointerException
<OK>

This is as far as I can get on this particular test application. Without
persistence.xml I can't create an EntityManagerFactory.
Re: Persistence and Java SE - Example [message #605485 is a reply to message #434564] Fri, 24 August 2007 12:20 Go to previous message
Mark Hoffmann is currently offline Mark HoffmannFriend
Messages: 113
Registered: July 2009
Location: Jena
Senior Member
I have had som similar problems with the persistence.xml. This is what
my peristence.xml looks like:
<?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="name">
<provider>
oracle.toplink.essentials.PersistenceProvider
</provider>
<class>
model.Country</class>
<properties>
<property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="toplink.jdbc.url"
value="jdbc:mysql://servername:3306/databasename"/>
<property name="toplink.jdbc.user" value="username"/>
<property name="toplink.jdbc.password" value="password"/>
<property name="toplink.logging.level" value="INFO"/>
<property name="toplink.target-database" value="MySQL4"/>
<!-- <property name="toplink.ddl-generation" value="create-tables"/>-->
</properties>
</persistence-unit>
</persistence>

Sometimes I didn't get a predefined persistence.xml with the wizard. So
I saved my persistence.xml and copy it into the project again. But this
problem is not reproducable on my configuration.

Mark
Re: Persistence and Java SE - Example [message #605488 is a reply to message #434565] Fri, 24 August 2007 13:30 Go to previous message
Steve Ray is currently offline Steve RayFriend
Messages: 31
Registered: July 2009
Member
Even when I copy my old persistence.xml, it still fails.
Re: Persistence and Java SE - Example [message #605490 is a reply to message #434564] Fri, 24 August 2007 14:13 Go to previous message
Karen Butzke is currently offline Karen ButzkeFriend
Messages: 220
Registered: July 2009
Senior Member
> Eclipse Europa Full Install
> JPA SE application

> Steps:
> Connect to MySQL server.
> New JPA Project
> Target Runtime: <None> There does not appear to be a way to select the
> TopLink Essentials agent for creating SE applications.
> Configuration: Utility JPA project with Java 5.0
> <Next>
> <Next>
> Connection: mysql
> JPA implementation: Use implementation libary
> Persistent class management: Discover annotated classes automatically

You need to choose 'Annotated classes must be listed in the
persistence.xml' in the JPA project wizard or on the JPA properties page
for a project that is already created. Then when you generate entities,
the persistence.xml file will be synchronized. There is something
confusing going on with these actions, I am going to investigate and will
most likely enter a bug. 'Discover annotated class automatically' means
that the java files do not need to be listed in the persistence.xml file.
If you want them listed for your runtime application, do not choose this
option.

> Create orm.xml checked
> <Finish>
> Context Menu on Project: JPA Tools/Generate Entities
> Select MySQL server
> Synchronize Classes in persistence.xml CHECKED
> Three tables CHECKED
> <Finish>

> Problem Occurred: Synchronizing classes
> An internal error occurred during: "Synchronizing classes".
> java.lang.NullPointerException
> <OK>

It sounds like your persistence.xml file was not created correctly when
the project was orginally created (bug 187370). Could you verify that it
is a valid persistence.xml after the jpa project wizard has completed?
Otherwise, could you post the entire stack trace from this NPE? You can
find it in the Error Log.

> Wrapper classes generated
> No information placed in persistence.xml
> No information placed in orm.xml

We do not update the orm.xml file on entity generation, it only creates
java files. You do not need the orm.xml file unless you want to create
your entities in xml instead of java or if you want to override your java
entities in xml. You can also use the orm.xml file for persistence unit
defaults.

I hope this helps some, if you are still experiencing problems, please
post the fully stack traces.

Karen
Re: Persistence and Java SE - Example [message #605492 is a reply to message #434565] Fri, 24 August 2007 14:14 Go to previous message
Karen Butzke is currently offline Karen ButzkeFriend
Messages: 220
Registered: July 2009
Senior Member
The persistence.xml file is sometimes not created correctly, this is
documented in bug 187370.

Karen
Re: Persistence and Java SE - Example [message #605494 is a reply to message #434566] Fri, 24 August 2007 14:15 Go to previous message
Karen Butzke is currently offline Karen ButzkeFriend
Messages: 220
Registered: July 2009
Senior Member
It sounds like things might be in a bad state at this point, have you
tried restarting Eclipse after making the persistence.xml a valid xml file?

Karen
Re: Persistence and Java SE - Example [message #605496 is a reply to message #434567] Wed, 29 August 2007 13:55 Go to previous message
Steve Ray is currently offline Steve RayFriend
Messages: 31
Registered: July 2009
Member
I got farther but still have problems: See below:

Trying to create a new SE, JPA project in the Europa release of Eclipse.
Using glassfish, toplink-essentials and MySQL.

NOTE:
************************************************************ *********************************************************
Projects that were created with Eclipse 3.2 and Dali 0.5 still work.
Java Projects created with Europa that manually add persistence work.
Running into issues with a new JPA project using JPA wizards in Europa.

New JPA Project
************************************************************ *********************************************************
Name: JPA_2
Project Contents: Use default [checked]
Target Runtime: <None>
Configurations: Utility JPA project with Java 6.0
EAR Membership: Add project to an EAR [unchecked]
<Next>
<Next>
Platform: Generic
Connection: mysql
SQL Model-JDBC Connection
Name: mysql
Description:
Auto-connect when the wizards finished or when Data Source Explorer
opens. [checked]
<NEXT>

Driver: MySQL JDBC Driver 5.0.6
Database: javashare
URL: jdbc:mysql://saturna.ca.boeing.com:3306/javashare
UserName: JavaFriends
Password: ********
Save Password [checked]
<Test Connection> Ping succeeded!
<Next>
<Finish>

Platform: Generic
Connection: mysql
JPA implementation: Use implementation library: <None>
Persistent class management: Annotated classes must be listed in
persistence.xml
Create orm.xml [unchecked]
<Finish>

Package Explorer
JPA_2
Context Menu: JPA Tools/Generate Entities...
Connection: MySQL 5.0.6
Schema: javashare
<Next>
Source folder: JPA_2/src
Package: (default) // For sample project only.
Synchronize Classes in persistence.xml [checked]
<Select All> // Three simple tables.
<Finish>

Added a simple class, JPA_2, to contain "main" which retrieves the first
record and displays its fields to the console.
The import javax.persistence cannot be resolved.
Package Explorer
JPA_2
Context Menu: Properties
Tree: Java Build Path
Tab: Libraries
<Add External JARs...>
mysql-connector-java-5.0.6-bin.jar
<Open>
<Add External JARs...>
toplink-essentials.jar
<Open>
<OK>

Menu: Run/Open Run Dialog...
New Launch Configuration
Tab: Main
Name: JPA_2
Project: JPA_2
Main class: JPA_2
Tab: Arguments
Program arguments:
VM arguments: -javaagent:"C:\Documents and Settings\rt954c\My
Documents\workspace\glassfish-persistence\toplink-essentials -agent.jar "
<Apply>
<Run>

Runtime Errors:
************************************************************ *********************************************************
[TopLink Info]: 2007.08.28 09:07:22.964--ServerSession(6889270)--TopLink,
version: Oracle TopLink Essentials - 2.0 (Build b48-beta3 (05/23/2007))
Exception in thread "main" Local Exception Stack:
Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0 (Build b48-beta3
(05/23/2007))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: [Microsoft][ODBC Driver
Manager] Data source name not found and no default driver specified
Error Code: 0
at
oracle.toplink.essentials.exceptions.DatabaseException.sqlEx ception(DatabaseException.java:305)
at
oracle.toplink.essentials.sessions.DefaultConnector.connect( DefaultConnector.java:102)
at
oracle.toplink.essentials.sessions.DatasourceLogin.connectTo Datasource(DatasourceLogin.java:185)
at
oracle.toplink.essentials.internal.sessions.DatabaseSessionI mpl.loginAndDetectDatasource(DatabaseSessionImpl.java:552)
at
oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvi der.login(EntityManagerFactoryProvider.java:221)
at
oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSet upImpl.deploy(EntityManagerSetupImpl.java:227)
at
oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManag erFactoryImpl.getServerSession(EntityManagerFactoryImpl.java :93)
at
oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManag erFactoryImpl.createEntityManagerImpl(EntityManagerFactoryIm pl.java:126)
at
oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManag erFactoryImpl.createEntityManagerImpl(EntityManagerFactoryIm pl.java:120)
at
oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerFac toryImpl.createEntityManager(EntityManagerFactoryImpl.java:9 1)
at JPA_2.main(JPA_2.java:24)
Caused by: java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data
source name not found and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at
oracle.toplink.essentials.sessions.DefaultConnector.connect( DefaultConnector.java:100)
... 9 more

Manually build persistence.xml
************************************************************ *********************************************************
<?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="JPA_2">
<provider>
oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvi der
</provider>
<class>TInterestLinks</class>
<class>TInterests</class>
<class>TMembers</class>
<properties>
<property name="toplink.jdbc.url"
value="jdbc:mysql://saturna.ca.boeing.com/javashare" />
<property name="toplink.jdbc.driver"
value="com.mysql.jdbc.Driver" />
<property name="toplink.jdbc.user" value="JavaFriends" />
<property name="toplink.jdbc.password" value="ShareTheFun" />
</properties>
</persistence-unit>
</persistence>

Runtime Errors:
************************************************************ *********************************************************
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(Un known
Source)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(U nknown
Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izerAgent.initializeFromAgent(JavaSECMPInitializerAgent.java :69)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izerAgent.premain(JavaSECMPInitializerAgent.java:62)
... 6 more
Caused by: javax.persistence.PersistenceException: Exception
[TOPLINK-28018] (Oracle TopLink Essentials - 2.0 (Build b48-beta3
(05/23/2007))):
oracle.toplink.essentials.exceptions.EntityManagerSetupExcep tion
Exception Description: predeploy for PersistenceUnit [JPA_2] failed.
Internal Exception: Exception [TOPLINK-7155] (Oracle TopLink Essentials -
2.0 (Build b48-beta3 (05/23/2007))):
oracle.toplink.essentials.exceptions.ValidationException
Exception Description: The type [class java.lang.Object] for the attribute
[activeSubTeam] on the entity class [class TInterests] is not a valid type
for a serialized mapping. The attribute type must implement the
Serializable interface.
at
oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSet upImpl.predeploy(EntityManagerSetupImpl.java:630)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izer.callPredeploy(JavaSECMPInitializer.java:171)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izer.initPersistenceUnits(JavaSECMPInitializer.java:251)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izer.initialize(JavaSECMPInitializer.java:267)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izer.initializeFromAgent(JavaSECMPInitializer.java:284)
... 12 more
Caused by: Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.0
(Build b48-beta3 (05/23/2007))):
oracle.toplink.essentials.exceptions.EntityManagerSetupExcep tion
Exception Description: predeploy for PersistenceUnit [JPA_2] failed.
Internal Exception: Exception [TOPLINK-7155] (Oracle TopLink Essentials -
2.0 (Build b48-beta3 (05/23/2007))):
oracle.toplink.essentials.exceptions.ValidationException
Exception Description: The type [class java.lang.Object] for the attribute
[activeSubTeam] on the entity class [class TInterests] is not a valid type
for a serialized mapping. The attribute type must implement the
Serializable interface.
at
oracle.toplink.essentials.exceptions.EntityManagerSetupExcep tion.predeployFailed(EntityManagerSetupException.java:228)
... 17 more
Caused by: Exception [TOPLINK-7155] (Oracle TopLink Essentials - 2.0
(Build b48-beta3 (05/23/2007))):
oracle.toplink.essentials.exceptions.ValidationException
Exception Description: The type [class java.lang.Object] for the attribute
[activeSubTeam] on the entity class [class TInterests] is not a valid type
for a serialized mapping. The attribute type must implement the
Serializable interface.
at
oracle.toplink.essentials.exceptions.ValidationException.inv alidTypeForSerializedAttribute(ValidationException.java:963)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.Metadat aValidator.throwInvalidTypeForSerializedAttribute(MetadataVa lidator.java:254)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.DirectAccessor.processSerialized(DirectAccessor.java:302)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.DirectAccessor.processJPAConverters(DirectAccessor.java:2 49)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.DirectAccessor.processMappingConverter(DirectAccessor.jav a:287)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.BasicAccessor.processDirectToFieldMapping(BasicAccessor.j ava:188)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.BasicAccessor.process(BasicAccessor.java:160)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.ClassAccessor.processAccessor(ClassAccessor.java:528)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.ClassAccessor.processAccessorFields(ClassAccessor.java:54 1)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.ClassAccessor.processAccessors(ClassAccessor.java:567)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.ClassAccessor.process(ClassAccessor.java:498)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.Metadat aProcessor.processAnnotations(MetadataProcessor.java:240)
at
oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUn itProcessor.processORMetadata(PersistenceUnitProcessor.java: 369)
at
oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSet upImpl.predeploy(EntityManagerSetupImpl.java:599)
... 16 more
FATAL ERROR in native method: processing of -javaagent failed
Exception in thread "main"

Syntax Errors show up after trying to run
************************************************************ *********************************************************
Schema "JavaFriends" cannot be resolved for table "t_Members" ...
Schema "JavaFriends" cannot be resolved for table "t_Interest_Links" ...
Schema "JavaFriends" cannot be resolved for table "t_Interests" ...

The only place "JavaFriends" added to the project is as the User property
when setting up the mysql driver connection and the persistence.xml file.
The database schema in this case is "javashare"
Re: Persistence and Java SE - Example [message #605499 is a reply to message #434570] Wed, 29 August 2007 20:40 Go to previous message
Karen Butzke is currently offline Karen ButzkeFriend
Messages: 220
Registered: July 2009
Senior Member
> Manually build persistence.xml
>
************************************************************ *********************************************************
> <?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="JPA_2">
> <provider>
> oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvi der
> </provider>
> <class>TInterestLinks</class>
> <class>TInterests</class>
> <class>TMembers</class>
> <properties>
> <property name="toplink.jdbc.url"
> value="jdbc:mysql://saturna.ca.boeing.com/javashare" />
> <property name="toplink.jdbc.driver"
> value="com.mysql.jdbc.Driver" />
> <property name="toplink.jdbc.user" value="JavaFriends" />
> <property name="toplink.jdbc.password" value="ShareTheFun" />
> </properties>
> </persistence-unit>
> </persistence>

Dali does not support editing the properties in the persistence.xml.
These are specific to TopLink Essentials (or whatever persistence
provider). You will have to edit the persistence.xml manually to include
the provider and the properties.

> Runtime Errors:

Could you post the TInterests class so I can see what might be mapped
incorrectly?


> Schema "JavaFriends" cannot be resolved for table "t_Members" ...
> Schema "JavaFriends" cannot be resolved for table "t_Interest_Links" ...
> Schema "JavaFriends" cannot be resolved for table "t_Interests" ...

> The only place "JavaFriends" added to the project is as the User property
> when setting up the mysql driver connection and the persistence.xml file.
> The database schema in this case is "javashare"

Dali is using the user name "JavaFriends" as the default schema. To use
the correct schema, you either need to specify it everywhere you specify a
table or edit the orm.xml to include a persistence unit default schema of
"javashare". You can do that in the JPA Details Persistence Unit section.

<?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">
<persistence-unit-metadata>
<persistence-unit-defaults>
<schema>javashare</schema>
</persistence-unit-defaults>
</persistence-unit-metadata>
</entity-mappings>
Re: Persistence and Java SE - Example [message #605502 is a reply to message #434570] Thu, 30 August 2007 10:12 Go to previous message
Mark Hoffmann is currently offline Mark HoffmannFriend
Messages: 113
Registered: July 2009
Location: Jena
Senior Member
This is a multi-part message in MIME format.
--------------050901090004000001080402
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Hello,

I've succesfully created an SE Project:
1. create JPA project:

- Target runtime: none Configurations: Default Configurations -> NEXT
- NEXT
- Select you Connection
- I neither used Implementation from server-runtime nor an
implementation library (I added the jar later to the build-path)
- check "Annotated classes must be listed in persistence.xml"
- uncheck "Create orm.xml" -> FINISH

2. Now go to the project properties - Java Build Path - Libraries - add
external jars. Add toplink-essentials.jar and the
mysql-connector-java-5.x.x-bin.jar. Now press ok.

3. I attached you my persistence.xml. For SE project a took another provider

4. now i created the entities, a main class, db-structure

5. creating entites from a existing schema works also well for me.

I hope this will help you

Mark



--------------050901090004000001080402
Content-Type: text/xml;
name="persistence.xml"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="persistence.xml"

<?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="JPA2" transaction-type="RESOURCE_LOCAL">
<provider>
oracle.toplink.essentials.PersistenceProvider
</provider>
<class>
test.entities.Contact</class>
<class>
test.entities.Meeting</class>
<properties>
<property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="toplink.jdbc.url" value="jdbc:mysql://myserver:3306/test"/>
<property name="toplink.jdbc.user" value="myuser"/>
<property name="toplink.jdbc.password" value="mypassword"/>
<property name="toplink.logging.level" value="INFO"/>
<property name="toplink.target-database" value="MySQL4"/>
<!-- <property name="toplink.ddl-generation" value="create-tables"/>-->
</properties>
</persistence-unit>
</persistence>

--------------050901090004000001080402
Content-Type: text/plain;
name="Contact.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="Contact.java"

package test.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.ManyToMany;
import javax.persistence.JoinTable;
import javax.persistence.JoinColumn;

@Entity
@Table(schema="test", name = "contact")
public class Contact implements Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;

@Id
private int id = 0;

private String name = new String();

@ManyToMany
@JoinTable(name="contact_meeting", joinColumns = @JoinColumn(name="contact_id"), inverseJoinColumns = @JoinColumn(name="meeting_id"))
private Collection<Meeting> meetings = new ArrayList<Meeting>(1);

/**
* @return Liefert das Attribut id
*/
public int getId() {
return id;
}

/**
* @return Liefert das Attribut name
*/
public String getName() {
return name;
}

/**
* @return Liefert das Attribut meetings
*/
public Collection<Meeting> getMeetings() {
return meetings;
}

}

--------------050901090004000001080402
Content-Type: text/plain;
name="Main.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="Main.java"

package test.main;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import test.entities.Contact;
import test.entities.Meeting;

public class Main {

/**
* @param args
*/
public static void main(String[] args) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPA2");
/*
* EntityManager holen
*/
EntityManager em = emf.createEntityManager();

Contact c = em.find(Contact.class, 1);
System.out.println("Name: " + c.getName());
for (Meeting m : c.getMeetings()) {
System.out.println("Meeting: " + m.getDescription());
}
}

}

--------------050901090004000001080402
Content-Type: text/plain;
name="Meeting.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="Meeting.java"

package test.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Id;
import javax.persistence.Column;
import javax.persistence.ManyToMany;

@Entity
@Table(schema="test", name = "meeting")
public class Meeting implements Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;

@Id
@Column(table="meeting", name = "id")
private int id = 0;

private String description = new String();

@ManyToMany(targetEntity=test.entities.Contact.class, mappedBy = "meetings")
private Collection<Contact> attendees = new ArrayList<Contact>(1);

/**
* @return Liefert das Attribut id
*/
public int getId() {
return id;
}

/**
* @return Liefert das Attribut description
*/
public String getDescription() {
return description;
}

/**
* @return Liefert das Attribut attendees
*/
public Collection<Contact> getAttendees() {
return attendees;
}

}

--------------050901090004000001080402
Content-Type: text/plain;
name="script.sql.ddl"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="script.sql.ddl"

Q1JFQVRFIFRBQkxFIGNvbnRhY3QgKA0KCWlkIElOVCBERUZBVUxUICcnIE5P VCBOVUxMLA0K
CW5hbWUgVkFSQ0hBUigyNTUpIERFRkFVTFQgJycgTk9UIE5VTEwsDQoJUFJJ TUFSWSBLRVkg
KGlkKQ0KKSBFTkdJTkU9TXlJU0FNOw0KDQpDUkVBVEUgVEFCTEUgY29udGFj dF9tZWV0aW5n
ICgNCgljb250YWN0X2lkIElOVCBERUZBVUxUICcnIE5PVCBOVUxMLA0KCW1l ZXRpbmdfaWQg
SU5UIERFRkFVTFQgJycgTk9UIE5VTEwNCikgRU5HSU5FPU15SVNBTTsNCg0K Q1JFQVRFIFRB
QkxFIG1lZXRpbmcgKA0KCWlkIElOVCBERUZBVUxUICcnIE5PVCBOVUxMLA0K CWRlc2NyaXB0
aW9uIFZBUkNIQVIoMjU1KSBERUZBVUxUICcnIE5PVCBOVUxMLA0KCVBSSU1B UlkgS0VZIChp
ZCkNCikgRU5HSU5FPU15SVNBTTs=
--------------050901090004000001080402--
Re: Persistence and Java SE - Example [message #605504 is a reply to message #434571] Thu, 30 August 2007 13:25 Go to previous message
Steve Ray is currently offline Steve RayFriend
Messages: 31
Registered: July 2009
Member
OK, no longer seeing syntax error when I try and run, however, still
getting runtime errors. Looks like a problem with persistence XML. Since
persistence.xml has to be created manually, is there any documentation on
how to do so?


java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(Un known
Source)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(U nknown
Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izerAgent.initializeFromAgent(JavaSECMPInitializerAgent.java :69)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izerAgent.premain(JavaSECMPInitializerAgent.java:62)
... 6 more
Caused by: Exception [TOPLINK-30004] (Oracle TopLink Essentials - 2.0
(Build b48-beta3 (05/23/2007))):
oracle.toplink.essentials.exceptions.PersistenceUnitLoadingE xception
Exception Description: An exception was thrown while processing
persistence.xml from URL:
file:/C:/Documents%20and%20Settings/rt954c/My%20Documents/wo rkspace/JPA_2/build/classes/
Internal Exception:
(1. cvc-complex-type.2.4.a: Invalid content was found starting with
element 'provider'. One of
'{"http://java.sun.com/xml/ns/persistence":mapping-file,
"http://java.sun.com/xml/ns/persistence":jar-file,
"http://java.sun.com/xml/ns/persistence":class,
"http://java.sun.com/xml/ns/persistence":exclude-unlisted-classes,
"http://java.sun.com/xml/ns/persistence":properties}' is expected.)
at
oracle.toplink.essentials.exceptions.PersistenceUnitLoadingE xception.exceptionProcessingPersistenceXML(PersistenceUnitLo adingException.java:134)
at
oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUn itProcessor.processPersistenceXML(PersistenceUnitProcessor.j ava:161)
at
oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUn itProcessor.processPersistenceArchive(PersistenceUnitProcess or.java:99)
at
oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUn itProcessor.getPersistenceUnits(PersistenceUnitProcessor.jav a:89)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izer.initPersistenceUnits(JavaSECMPInitializer.java:248)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izer.initialize(JavaSECMPInitializer.java:267)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izer.initializeFromAgent(JavaSECMPInitializer.java:284)
... 12 more
Caused by:
(1. cvc-complex-type.2.4.a: Invalid content was found starting with
element 'provider'. One of
'{"http://java.sun.com/xml/ns/persistence":mapping-file,
"http://java.sun.com/xml/ns/persistence":jar-file,
"http://java.sun.com/xml/ns/persistence":class,
"http://java.sun.com/xml/ns/persistence":exclude-unlisted-classes,
"http://java.sun.com/xml/ns/persistence":properties}' is expected.)
at
oracle.toplink.essentials.internal.ejb.cmp3.xml.parser.XMLEx ceptionHandler.error(XMLExceptionHandler.java:52)
at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper. error(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.rep ortError(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.rep ortError(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidato r$XSIErrorReporter.reportError(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidato r.reportSchemaError(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidato r.handleStartElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidato r.startElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScanner Impl.scanStartElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl$FragmentContentDriver.next(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl.next(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScanner Impl.next(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(U nknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSA XParser.parse(Unknown
Source)
at
oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUn itProcessor.processPersistenceXML(PersistenceUnitProcessor.j ava:151)
... 17 more
FATAL ERROR in native method: processing of -javaagent failed
Exception in thread "main"
Here's TInterests.java

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="t_Interests")
public class TInterests implements Serializable {
@Id
@Column(name="interest_id")
private int interestId;

@Column(name="active_sub_team")
private Object activeSubTeam;

private String name;

private String description;

private static final long serialVersionUID = 1L;

public TInterests() {
super();
}

public int getInterestId() {
return this.interestId;
}

public void setInterestId(int interestId) {
this.interestId = interestId;
}

public Object getActiveSubTeam() {
return this.activeSubTeam;
}

public void setActiveSubTeam(Object activeSubTeam) {
this.activeSubTeam = activeSubTeam;
}

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return this.description;
}

public void setDescription(String description) {
this.description = description;
}

}


And persistence.xml

<?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="JPA_2">
<mapping-file>META-INF/orm.xml</mapping-file>

<provider> oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvi der </provider>
<class>TInterestLinks</class>
<class>TInterests</class>
<class>TMembers</class>
- <properties>
<property name="toplink.jdbc.url"
value="jdbc:mysql://saturna.ca.boeing.com/javashare" />
<property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="toplink.jdbc.user" value="JavaFriends" />
<property name="toplink.jdbc.password" value="ShareTheFun" />
</properties>
</persistence-unit>
</persistence>

And orm.xml:

<?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">
- <persistence-unit-metadata>
- <persistence-unit-defaults>
<schema>javashare</schema>
</persistence-unit-defaults>
</persistence-unit-metadata>
</entity-mappings>
Re: Persistence and Java SE - Example [message #605508 is a reply to message #434573] Thu, 30 August 2007 14:24 Go to previous message
Karen Butzke is currently offline Karen ButzkeFriend
Messages: 220
Registered: July 2009
Senior Member
If you edit the persistence.xml from within eclipse you should see the
same error. The element <provider> belongs before the <mapping-file
element>. Using eclipse you should be able to at least get schema
validation. TopLink Essentials documentation on the persistence.xml
properties they support is found at
http://www.oracle.com/technology/products/ias/toplink/JPA/es sentials/toplink-jpa-extensions.html
You can also look at the EJB 3.0 persistence spec.


The original runtime exception you were getting is because of the mapping
@Column(name="active_sub_team")
private Object activeSubTeam;

We generated type Object probably because the data type of active_sub_team
is something we don't know how to handle. You will have to change what we
generated since in JPA you cannot map Object as a direct mapping. The
error message was trying to say that Object was not Serializable which is
one way to map a type as a direct mapping.

Karen
Re: Persistence and Java SE - Example [message #605510 is a reply to message #434574] Thu, 30 August 2007 19:22 Go to previous message
Steve Ray is currently offline Steve RayFriend
Messages: 31
Registered: July 2009
Member
Finally. Thanks for your help. A couple of questions:

I have a table with a boolean in it:

Table t_Interests has a field, active_sub_team defined as a Boolean.

Dali 0.5 generated TInterest.java working the pre-Europa projects.
@Column(name="active_sub_team")
private short activeSubTeam;

Eclipse Europa, is different causing another exception.
@Column(name="active_sub_team")
private Object activeSubTeam;

Exceptions:
**********************************************************
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(Un known
Source)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(U nknown
Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izerAgent.initializeFromAgent(JavaSECMPInitializerAgent.java :69)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izerAgent.premain(JavaSECMPInitializerAgent.java:62)
... 6 more
Caused by: javax.persistence.PersistenceException: Exception
[TOPLINK-28018] (Oracle TopLink Essentials - 2.0 (Build b48-beta3
(05/23/2007))):
oracle.toplink.essentials.exceptions.EntityManagerSetupExcep tion
Exception Description: predeploy for PersistenceUnit [JPA_2] failed.
Internal Exception: Exception [TOPLINK-7155] (Oracle TopLink Essentials -
2.0 (Build b48-beta3 (05/23/2007))):
oracle.toplink.essentials.exceptions.ValidationException
Exception Description: The type [class java.lang.Object] for the attribute
[activeSubTeam] on the entity class [class TInterests] is not a valid type
for a serialized mapping. The attribute type must implement the
Serializable interface.
at
oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSet upImpl.predeploy(EntityManagerSetupImpl.java:630)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izer.callPredeploy(JavaSECMPInitializer.java:171)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izer.initPersistenceUnits(JavaSECMPInitializer.java:251)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izer.initialize(JavaSECMPInitializer.java:267)
at
oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitial izer.initializeFromAgent(JavaSECMPInitializer.java:284)
... 12 more
Caused by: Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.0
(Build b48-beta3 (05/23/2007))):
oracle.toplink.essentials.exceptions.EntityManagerSetupExcep tion
Exception Description: predeploy for PersistenceUnit [JPA_2] failed.
Internal Exception: Exception [TOPLINK-7155] (Oracle TopLink Essentials -
2.0 (Build b48-beta3 (05/23/2007))):
oracle.toplink.essentials.exceptions.ValidationException
Exception Description: The type [class java.lang.Object] for the attribute
[activeSubTeam] on the entity class [class TInterests] is not a valid type
for a serialized mapping. The attribute type must implement the
Serializable interface.
at
oracle.toplink.essentials.exceptions.EntityManagerSetupExcep tion.predeployFailed(EntityManagerSetupException.java:228)
... 17 more
Caused by: Exception [TOPLINK-7155] (Oracle TopLink Essentials - 2.0
(Build b48-beta3 (05/23/2007))):
oracle.toplink.essentials.exceptions.ValidationException
Exception Description: The type [class java.lang.Object] for the attribute
[activeSubTeam] on the entity class [class TInterests] is not a valid type
for a serialized mapping. The attribute type must implement the
Serializable interface.
at
oracle.toplink.essentials.exceptions.ValidationException.inv alidTypeForSerializedAttribute(ValidationException.java:963)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.Metadat aValidator.throwInvalidTypeForSerializedAttribute(MetadataVa lidator.java:254)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.DirectAccessor.processSerialized(DirectAccessor.java:302)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.DirectAccessor.processJPAConverters(DirectAccessor.java:2 49)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.DirectAccessor.processMappingConverter(DirectAccessor.jav a:287)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.BasicAccessor.processDirectToFieldMapping(BasicAccessor.j ava:188)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.BasicAccessor.process(BasicAccessor.java:160)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.ClassAccessor.processAccessor(ClassAccessor.java:528)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.ClassAccessor.processAccessorFields(ClassAccessor.java:54 1)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.ClassAccessor.processAccessors(ClassAccessor.java:567)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.accesso rs.ClassAccessor.process(ClassAccessor.java:498)
at
oracle.toplink.essentials.internal.ejb.cmp3.metadata.Metadat aProcessor.processAnnotations(MetadataProcessor.java:240)
at
oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUn itProcessor.processORMetadata(PersistenceUnitProcessor.java: 369)
at
oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSet upImpl.predeploy(EntityManagerSetupImpl.java:599)
... 16 more
FATAL ERROR in native method: processing of -javaagent failed
Exception in thread "main"

Secondly:

In a project built with Dali 0.5, I had created a persistence.xml file
with two persistence-unit definitions. In Europa, it is flagging an error
about this. Does this mean that the schema has changed? Are we really
locked to a single DB for a persistence project or is there another
mechanism to achieve this? While the project I created was for
instructional purposes on how the same project could use identical
databases implemented in MySQL and Access, a real world application may
need to pull data from multiple sources. In fact I can think of a few
future projects that would work best with multiple distinct databases.

Fortunately, the Europa project with two persistence-unit definitions
still works and allows me to select the desired persistence-unit to use.
The createEntityManagerFactory also seems to be designed with this in mind.

EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPA_2");

If it didn't, then we shouldn't have to specify the persistence-unit name.

OK, I'm confused. According to
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd multiple
persistence-unit definitions are allowed.
<xsd:element name="persistence-unit" minOccurs="0" maxOccurs="unbounded">

Why am I getting an error then in my persistence.xml?

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

....
Severity and Description Path Resource Location Creation Time Id
Multiple persistence units defined JPA_2/src/META-INF persistence.xml line
2 1188499881616 27799
Re: Persistence and Java SE - Example [message #605513 is a reply to message #434575] Fri, 31 August 2007 14:51 Go to previous message
Karen Butzke is currently offline Karen ButzkeFriend
Messages: 220
Registered: July 2009
Senior Member
Steve Ray wrote:

> I have a table with a boolean in it:

> Table t_Interests has a field, active_sub_team defined as a Boolean.

> Dali 0.5 generated TInterest.java working the pre-Europa projects.
> @Column(name="active_sub_team")
> private short activeSubTeam;

> Eclipse Europa, is different causing another exception.
> @Column(name="active_sub_team")
> private Object activeSubTeam;

The major change to entity generation from .5 to 1.0 was the switch from
WTP's RDB to the DataTools project (DTP). This could be a bug in DTP's
mySQL support. For now you will just have to change the type of the
attribute after generation. Could you enter a bug against Dali for this
problem?

> Secondly:

> In a project built with Dali 0.5, I had created a persistence.xml file
> with two persistence-unit definitions. In Europa, it is flagging an error
> about this. Does this mean that the schema has changed? Are we really
> locked to a single DB for a persistence project or is there another
> mechanism to achieve this? While the project I created was for
> instructional purposes on how the same project could use identical
> databases implemented in MySQL and Access, a real world application may
> need to pull data from multiple sources. In fact I can think of a few
> future projects that would work best with multiple distinct databases.

> Why am I getting an error then in my persistence.xml?

We should make this a warning not an error and make it clear that *Dali*
doesn't support multiple persistence units. The JPA spec certainly does.
I agree that an error is too strong. Could you enter a bug to change this
from an error to a warning and make the message clearer?

We have an enhancement request (194833) open for supporting multiple
persistence units. The difficultly comes if the persistence units have
overlapping classes. The tooling doesn't know which context to support
for defaults and validation.

Thanks for reporting these issues.

Karen
Previous Topic:Many problems with Dali
Next Topic:can't add java persistence to java project
Goto Forum:
  


Current Time: Fri Mar 29 01:15:41 GMT 2024

Powered by FUDForum. Page generated in 0.06097 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top