Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » EclipseLink does not store in database
EclipseLink does not store in database [message #388464] Sat, 30 May 2009 04:24 Go to next message
Eclipse User
Originally posted by: tilzi83.free.fr

Hi,

i'm trying to move from Hibernate to EclipseLink, everything (in the
code) seems to work fine :
- Tables are created
- em.find() returns valid objects

but nothing is stored in the database when i call em.persist() or
em.merge() !

Here is the persitence.xml :

<persistence-unit name="entity-test" >
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider >

<class>(...)<class>
<properties>

<property name="eclipselink.logging.level" value="WARNING"/>
<property name="eclipselink.jdbc.url"
value="jdbc:mysql://localhost:3306/DB"/>
<property name="eclipselink.jdbc.user" value="XXX"/>
<property name="eclipselink.jdbc.password" value="YYY"/>
<property name="eclipselink.jdbc.driver"
value="com.mysql.jdbc.Driver"/>
<property name="eclipselink.jdbc.read-connections.min" value="1"/>
<property name="eclipselink.jdbc.write-connections.min" value="1"/>
<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="MySQL"/>
<property name="eclipselink.target-server" value="None" />



<property name="hibernate.connection.driver_class"
value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.username" value="XXX" />
<property name="hibernate.connection.password" value="YYY" />
<property name="hibernate.connection.url"
value="jdbc:mysql://localhost:3306/DB" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
</properties>
</persistence-unit>



And a piece of code :

EntityManager em = emf.createEntityManager();
Currency euro = new Currency();
euro.setLongTerm("Euro");
euro.setShortTerm("e");
em.merge(euro);


After that, nothing is inserted in the database.
Any ideas ?
Re: EclipseLink does not store in database [message #388466 is a reply to message #388464] Sat, 30 May 2009 05:23 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom Eugelink
Messages: 807
Registered: July 2009
Senior Member
> EntityManager em = emf.createEntityManager();
> Currency euro = new Currency();
> euro.setLongTerm("Euro");
> euro.setShortTerm("e");
> em.merge(euro);

And what happens with em.persist(euro)?
Re: EclipseLink does not store in database [message #388470 is a reply to message #388466] Sat, 30 May 2009 14:49 Go to previous messageGo to next message
Eclipse User
Originally posted by: tilzi83.free.fr

tbee a écrit :
>> EntityManager em = emf.createEntityManager();
>> Currency euro = new Currency();
>> euro.setLongTerm("Euro");
>> euro.setShortTerm("e");
>> em.merge(euro);
>
> And what happens with em.persist(euro)?

nothing!

I've tried this :

Currency merged = em.merge(euro);
em.persist(merged);
em.persist(euro);

Only one warning while creating the EntityManagerFactory :

[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services
- 1.1.1.v20090430-r4097):
org.eclipse.persistence.exceptions.DatabaseException
Internal Exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table
'SEQUENCE' already exists
Error Code: 1050
Call: CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT
DECIMAL(38), PRIMARY KEY (SEQ_NAME))
Query: DataModifyQuery(sql="CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50)
NOT NULL, SEQ_COUNT DECIMAL(38), PRIMARY KEY (SEQ_NAME))")

This message seems harmless...
Re: EclipseLink does not store in database [message #388472 is a reply to message #388470] Sun, 31 May 2009 03:44 Go to previous messageGo to next message
Eclipse User
Originally posted by: tilzi83.free.fr

This is a multi-part message in MIME format.
--------------010107000005060803020200
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit

Mark Adams a
Re: EclipseLink does not store in database [message #388473 is a reply to message #388470] Sun, 31 May 2009 05:10 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom Eugelink
Messages: 807
Registered: July 2009
Senior Member
>
> Only one warning while creating the EntityManagerFactory :
>
> [EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services
> - 1.1.1.v20090430-r4097):
> org.eclipse.persistence.exceptions.DatabaseException
> Internal Exception:
> com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table
> 'SEQUENCE' already exists
> Error Code: 1050
> Call: CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT
> DECIMAL(38), PRIMARY KEY (SEQ_NAME))
> Query: DataModifyQuery(sql="CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50)
> NOT NULL, SEQ_COUNT DECIMAL(38), PRIMARY KEY (SEQ_NAME))")
>
> This message seems harmless...


This is not a warning. It tries to create the sequence table but did not succeed. So that means it can never create a primary key and as such can never persist a new object. It may also be the case that the EM is aware of this and doesn't even try. I'm not sure, though.

What happens if you also set the primary key with a value?

Tom
Re: EclipseLink does not store in database [message #388475 is a reply to message #388472] Sun, 31 May 2009 16:04 Go to previous messageGo to next message
Doug Clarke is currently offline Doug Clarke
Messages: 155
Registered: July 2009
Senior Member
Not sure if I missed something but I do not see and transaction control in
you examples. Are you running this code in a container manage transaction
session bean method?

If not you need to begin and commit the transaction.

em.getTransaction().begin();

em.persist(newObject);

em.getTransaction().commit();

Doug
Re: EclipseLink does not store in database [message #388481 is a reply to message #388475] Mon, 01 June 2009 03:11 Go to previous message
Eclipse User
Originally posted by: tilzi83.free.fr

Doug Clarke a écrit :
> Not sure if I missed something but I do not see and transaction control
> in you examples. Are you running this code in a container manage
> transaction session bean method?
>
> If not you need to begin and commit the transaction.
>
> em.getTransaction().begin();
>
> em.persist(newObject);
>
> em.getTransaction().commit();
>
> Doug
>

That is the solution!
In fact, my old Hibernate code was running in an EJB container.
The new code is a Junit test running in a Java SE environment.

Thank you everybody
Previous Topic:@Lob @Column (length=16777215) doesn't work with MySql to get a MEDIUMBLOB
Next Topic:QueryValueHolder Strategy for Better Memory Management
Goto Forum:
  


Current Time: Thu Aug 21 02:36:26 EDT 2014

Powered by FUDForum. Page generated in 0.01639 seconds