Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Object Relational Mapping and the fly likes Issue with JPA + MySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Issue with JPA + MySQL" Watch "Issue with JPA + MySQL" New topic

Issue with JPA + MySQL

Saurav Chatterjee

Joined: Mar 31, 2005
Posts: 12
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 {

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) { = id;

public String getName() {
return name;
public void setName(String 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=""
<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.

I agree. Here's the link:
subject: Issue with JPA + MySQL