EclipseLink does not store in database [message #388464] |
Sat, 30 May 2009 08:24 |
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 #388470 is a reply to message #388466] |
Sat, 30 May 2009 18:49 |
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 #388481 is a reply to message #388475] |
Mon, 01 June 2009 07:11 |
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
|
|
|
Powered by
FUDForum. Page generated in 0.03384 seconds