Note that there are some explanatory texts on larger screens.

plurals
  1. POEclipselink JPA, Oracle, Weblogic, Calling Persist does not commit to database
    primarykey
    data
    text
    <p>I'm just starting to take a look at java persistence (at the moment with eclipse's default provider of eclipselink). Basically just creating an object and attempting to persist it to the db (Oracle). It was my understanding that the default transactionality should commit the new object to the database when the method returns but nothing seems to be happening. Any ideas?</p> <pre><code>@Stateless public class RegisterUser implements RegisterUserLocal { @PersistenceContext private EntityManager entityManager; public void registerNewUser(String username, String password){ User user = new User(); user.setPassword(password); user.setUsername(username); entityManager.persist(user); entityManager.getTransaction().commit(); } } </code></pre> <p>Persistence.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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"&gt; &lt;persistence-unit name="SCBCDEntities" transaction-type="RESOURCE_LOCAL"&gt; &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt; &lt;class&gt;examples.persistence.User&lt;/class&gt; &lt;properties&gt; &lt;property name="eclipselink.target-server" value="WebLogic_10"/&gt; &lt;property name="eclipselink.jdbc.driver" value="oracle.jdbc.OracleDriver"/&gt; &lt;property name="eclipselink.jdbc.url" value="jdbc:oracle:thin:@localhost:1521:db4"/&gt; &lt;property name="eclipselink.jdbc.user" value="SCBCD"/&gt; &lt;property name="eclipselink.jdbc.password" value="123456"/&gt; &lt;property name="eclipselink.logging.level" value="FINEST"/&gt; &lt;/properties&gt; &lt;/persistence-unit&gt; &lt;/persistence&gt; </code></pre> <p>Entity Class:</p> <pre><code>@Entity @Table(name="USERS") public class User implements Serializable { private static final long serialVersionUID = 1L; @Id private String username; private String password; public User() { } public String getUsername() { return this.username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return this.password; } public void setPassword(String password) { this.password = password; } } </code></pre> <p>Also, to respond to replies to this question, with the code I've listed the logs show a commit executing (some detail removed for brevity)</p> <pre><code>[EL Finest]: 2010-01-05 22:58:07.468--UnitOfWork(25499586)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel. Default (self-tuning)',5,Pooled Threads])--PERSIST operation called on: examples.persistence.User@191ed96. &lt;Jan 5, 2010 10:58:07 PM EST&gt; &lt;Debug&gt; &lt;JTA2PC&gt; &lt;BEA-000000&gt; &lt;BEA1-001959ECF50B251A451D: [EJB examples.session.stateless.RegisterUs er.registerNewUser(java.lang.String,java.lang.String)]: ServerTransactionImpl.commit()&gt; &lt;Jan 5, 2010 10:58:07 PM EST&gt; &lt;Debug&gt; &lt;JTA2PC&gt; &lt;BEA-000000&gt; &lt;BEA1-001959ECF50B251A451D: [EJB examples.session.stateless.RegisterUs er.registerNewUser(java.lang.String,java.lang.String)]: TX[BEA1-001959ECF50B251A451D] active--&gt;pre_preparing &lt;Jan 5, 2010 10:58:07 PM EST&gt; &lt;Debug&gt; &lt;JTA2PC&gt; &lt;BEA-000000&gt; &lt;SC[mr_domain+AdminServer] active--&gt;pre-preparing er.registerNewUser(java.lang.String,java.lang.String)]: TX[BEA1-001959ECF50B251A451D] prepared--&gt;committing &lt;Jan 5, 2010 10:58:07 PM EST&gt; &lt;Debug&gt; &lt;JTA2PC&gt; &lt;BEA-000000&gt; &lt;SC[mr_domain+AdminServer] pre-prepared--&gt;committed er.registerNewUser(java.lang.String,java.lang.String)]: TX[BEA1-001959ECF50B251A451D] committing--&gt;committed ... ... </code></pre> <p>but if I add 'flush' after the persist, I get 'notransaction'...</p> <pre><code>[EL Finest]: 2010-01-05 22:44:55.218--UnitOfWork(113017)--Thread(Thread[[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.De fault (self-tuning)',5,Pooled Threads])--PERSIST operation called on: examples.persistence.User@1717dea. &lt;Jan 5, 2010 10:44:55 PM EST&gt; &lt;Info&gt; &lt;EJB&gt; &lt;BEA-010227&gt; &lt;EJB Exception occurred during invocation from home or business: weblogic. ejb.container.internal.StatelessEJBLocalHomeImpl@1509b8 threw exception: javax.persistence.TransactionRequiredException: Exception Description: No transaction is currently active&gt; &lt;Jan 5, 2010 10:44:55 PM EST&gt; &lt;Debug&gt; &lt;JTA2PC&gt; &lt;BEA-000000&gt; &lt;BEA1-001859ECF50B251A451D: [EJB examples.session.stateless.RegisterUs er.registerNewUser(java.lang.String,java.lang.String)]: TX[BEA1-001859ECF50B251A451D] active--&gt;rolling back ... ... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload