• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Issue with JPA + MySQL

Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me first tell you that I am a rookie when it comes to JPA so I was just following the examples given in EJB3 in Action (albeit with some modification to simplify matters for me). I have installed MySQL and Weblogic 10 (10.3 most probably) and eclipse is the IDE. Here is the database table in question.

mysql> desc location;
| Field | Type | Null | Key | Default | Extra |
| id | int(11) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| description | varchar(20) | YES | | NULL | |

Here is the Entity Bean.

package intro.ejb3.entity;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Column;

public class Location implements java.io.Serializable {

private static final long serialVersionUID = 1L;

private long id;
private String name;
private String description;

public long getId() {
return id;
public void setId(long id) {
this.id = id;

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

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

Here is the corresponding persistence.xml.

<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
<persistence-unit name="actionBazaar">
<property name="kodo.jdbc.SynchronizeMappings" value="buildSchema"/>

And here is the Stateless Session Bean that is getting used as the client.

package intro.ejb3.session.stateless;

import intro.ejb3.entity.Location;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

public class EventProcessorBean implements EventProcessor {

private SessionContext sessionContext;

public EventProcessorBean() {

@PersistenceContext(unitName = "actionBazaar")
private EntityManager em;

public long addLocation(Location location) {
return save(location).getId();

public void m1() {

public void m2() {

private Location save(Location location) {
System.out.println("Before saving");
System.out.println("Location Id : " + location.getId());
return location;

When I call the addLocation operation I am getting a transaction time-out error from the 'persist' call (the 'Before saving' is getting printed to the server console). Any idea what can be the reason? Please note few things that may be of importance.

1. Initially I was getting some error saying cannot set autocommit true in a distributed transaction (2 phase commit was enable for the datasource). I removed that by selecting 1 phase commit.
2. Setting 1 phase commit resulted into open_jpa_... table related exception which I removed by creating that table manually.

CREATE TABLE openjpa_sequence_table (ID tinyint(4) NOT NULL, SEQUENCE_VALUE bigint(20) default NULL, PRIMARY KEY (ID))

3. Then when I called the operation it was not going to 'Before saving' line even. So I reverted back the configuration to 2 phase commit and then it started giving transaction time out.
4. The Driver class name (as from the Weblogic console) is com.mysql.jdbc.Driver.

    Bookmark Topic Watch Topic
  • New Topic