Results 1 to 1 of 1
  1. #1
    mrblack is offline Member
    Join Date
    Feb 2011
    Posts
    1
    Rep Power
    0

    Default 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:
    XML 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:
    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:
    XML 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:
    XML Code:
    INSERT INTO Binding VALUES ()
    instead of
    XML Code:
    INSERT INTO Binding VALUES (DEFAULT)
    Last edited by mrblack; 02-27-2011 at 03:48 PM. Reason: missed something

Similar Threads

  1. SSL exception in websphere 6.1
    By shyamsundar1.g in forum Advanced Java
    Replies: 0
    Last Post: 10-29-2009, 05:52 AM
  2. Guide of development of WebSphere
    By Albert in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 07-06-2007, 08:29 AM
  3. Websphere doubt
    By Peter in forum Other IDEs
    Replies: 1
    Last Post: 07-05-2007, 03:47 AM
  4. Manual of websphere
    By Marcus in forum Web Frameworks
    Replies: 1
    Last Post: 06-27-2007, 05:01 PM
  5. Who will know like connecting from Websphere
    By Albert in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 06-27-2007, 04:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •