Account Options

  1. Sign in
Google Groups Home
« Groups Home
JPA/EclipseLink 1.0.2 J2SE Project: emf.createEntityManager() truncates tables
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
awaw...@gmx.net  
View profile  
 More options Mar 1 2009, 12:26 pm
From: awaw...@gmx.net
Date: Sun, 1 Mar 2009 09:26:30 -0800 (PST)
Local: Sun, Mar 1 2009 12:26 pm
Subject: JPA/EclipseLink 1.0.2 J2SE Project: emf.createEntityManager() truncates tables
I followed your tutorial to setup a Java/JPA project.

I am using a MySQL 5  database together with the MySQLConnector v5.0.4
and EclipseLink 1.0.2.

I defined a set of additional entities. Automatic creation of DDL in
the database works. I successfully create some entries in the tables
programatically, starting with a JUnit4 Test.

The problem is, that everytime I create a new entity manager all
mapped tables are truncated. Thus, every query on a new entity manager
returns an empty result.

The test case:
  @Before
  public void setUp() throws Exception {
    emf = Persistence.createEntityManagerFactory("TestJPA");
  }

  @Test
  public void doNothing() {
    emf.createEntityManager().close();
  }

  @After
  public void tearDown() {
    emf.close();
  }

results in an empty database.

I am afraid, I have some kind of fundamental misunderstanding. Your
tutorial and all others that I have found do a setup (@Before) that
creates all queried data in advance, but it is never explain why. How
can I read peristed data? Is this truncation normal JPA behaviour and
simply used in a wrong way on my side, or is it an EclipseLink
implementation issue?

This is 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">
  <persistence-unit name="TestJPA" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</
provider>
    <class>model.Family</class>
    <class>model.Job</class>
    <class>model.Person</class>
    <class>model.OfficeJob</class>
    <class>model.OutdoorJob</class>
    <class>model.Animal</class>
    <properties>
      <property name="eclipselink.jdbc.url" value="jdbc:mysql://
localhost:3306/test01"/>
      <property name="eclipselink.jdbc.user" value="root"/>
      <property name="eclipselink.jdbc.password" value=""/>
      <property name="eclipselink.jdbc.driver"
value="com.mysql.jdbc.Driver"/>
      <property name="eclipselink.ddl-generation" value="drop-and-
create-tables" />
      <property name="eclipselink.ddl-generation.output-mode"
value="database" />
      <property name="eclipselink.target-database" value="Auto"/>
  </properties>
</persistence-unit>
</persistence>

Thank you for your help in advance,

Andi


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lars Vogel  
View profile  
 More options Mar 3 2009, 2:42 am
From: Lars Vogel <lars.vo...@googlemail.com>
Date: Tue, 3 Mar 2009 08:42:17 +0100
Local: Tues, Mar 3 2009 2:42 am
Subject: Re: JPA/EclipseLink 1.0.2 J2SE Project: emf.createEntityManager() truncates tables

Hi,
@Setup runs before every test. Combined with "drop-and-create-tables" I
would also expect that the data of the unit tests is lost. For my example
this is intended as I want to have a reproducable unit test.

If you want to have some data I suggest to create data in your setup
routine.

Best regards, Lars

2009/3/1 <awaw...@gmx.net>

--
Lars
http://www.vogella.de - Tutorial about Java, Eclipse and Web programming

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "JPA/EclipseLink 1.0.2 J2SE Project: emf.createEntityManager() truncates tables - SOLVED" by awaw...@gmx.net
awaw...@gmx.net  
View profile  
 More options Mar 3 2009, 7:25 am
From: awaw...@gmx.net
Date: Tue, 3 Mar 2009 04:25:38 -0800 (PST)
Local: Tues, Mar 3 2009 7:25 am
Subject: Re: JPA/EclipseLink 1.0.2 J2SE Project: emf.createEntityManager() truncates tables - SOLVED
Hi Lars,

thank you your answer. Setting
<property name="eclipselink.ddl-generation" value="none" />
has solved the problem. My misunderstanding was that these properties
configure Eclipse's "JPA Tools -> Generate DDL ..." functionality.
Instead,
the DDL generation is done automatically every time an entity manager
is created.

Best regards, Andi


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »