OpenJPA + DB2 + WebSphere
Hi, I'm working on my school project where I need to create SessionBeans Entity Classes corresponding to database which is in this case DB2. Right now I'm living my worst programming nightmare, because I have been trying to figure out how to persist simple Entity with single attribute (generated ID), with no effect for 5 days. I'm able to persist Entity with two or more attributes, but I can't crack this one. After persist of following Entity I'm getting as it's ID null instead of generated value from DB2. Can somebody help me please? Thx
Entity class:
Code:
package entity;
import java.io.Serializable;
import javax.persistence.*;
@Entity
@Table(name = "BINDING")
public class Binding implements Serializable {
private static final long serialVersionUID = 1L;
private Long bindingId;
public Binding() {
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "BINDING_ID", unique = true, nullable = false)
public Long getBindingId() {
return this.bindingId;
}
public void setBindingId(Long bindingId) {
this.bindingId = bindingId;
}
}
persistence.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="AppEJB" transaction-type="JTA">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>jdbc/datasource</jta-data-source>
<class>entity.Binding</class>
<properties>
<property name="openjpa.jdbc.Schema" value="BOOKSTORE" />
<property name="openjpa.jdbc.DBDictionary" value="db2" />
</properties>
</persistence-unit>
</persistence>
Manage for entity:
Code:
package manager;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import entity.Binding;
@Stateless(name = "bookManager", mappedName = "bookManager")
public class BookManager implements BookManagerRemote {
@PersistenceContext(unitName = "AppEJB")
private EntityManager em;
protected EntityManager getEntityManager() {
return em;
}
public BookManager() {
}
@Override
public Binding create(Binding binding) {
em.persist(binding);
return binding;
}
}
I think the problem is that this generates SQL:
Code:
INSERT INTO Binding VALUES ()
instead of
Code:
INSERT INTO Binding VALUES (DEFAULT)