openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Iron Luca <ironl...@gmail.com>
Subject Terrible Problem with EntityManager find method with OpenJPA
Date Sun, 03 Oct 2010 07:23:30 GMT
Hi All,

I am new to this forum & was thinking is someone could help me out. I have a
persistent class:

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table
public class TestTable {

        @Id
        @Column
        protected String id;

        @Column
        protected String text;

        public String getId() {
                return id;
        }

        public void setId(String id) {
                this.id = id;
        }

        public String getText() {
                return text;
        }

        public void setText(String text) {
                this.text = text;
        }
}

>From the code below, I can insert entities in the database but (commented
out code) but getting an exception while finding any entity:

package com.wrwlf.test.dao;

import java.util.Properties;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import com.wrwlf.dao.client.Client;
import com.wrwlf.dao.client.ClientInfo;
import com.wrwlf.dao.client.TestTable;

public class DAOTest {

        /**
         * @param args
         */
        public static void main(String[] args) {
                // TODO Auto-generated method stub

                Properties props=new Properties();
                props.put("ConnectionURL",
"jdbc:mysql://localhost:3306/wrwlfdb");
                props.put("ConnectionDriverName", "com.mysql.jdbc.Driver");
                props.put("ConnectionUserName", "root");
                props.put("ConnectionPassword", "root");

                EntityManagerFactory
factory=Persistence.createEntityManagerFactory("masterdb");
                EntityManager manager=factory.createEntityManager();

                /*
                TestTable obj1=new TestTable();
                obj1.setId("id2");obj1.setText("again some text");

                manager.getTransaction().begin();
                manager.persist(obj1);
                manager.getTransaction().commit();
                */
                TestTable obj2=manager.find(TestTable.class, "id1");
                System.out.println(obj2);
        }

}

The exception is as follows:

109  masterdb  INFO   [main] openjpa.Runtime - Starting OpenJPA 2.0.1
265  masterdb  INFO   [main] openjpa.jdbc.JDBC - Using dictionary class
"org.apache.openjpa.jdbc.sql.MySQLDictionary".
Exception in thread "main" <openjpa-2.0.1-r422266:989424 nonfatal store
error> org.apache.openjpa.persistence.EntityNotFoundException: Cannot
perform find using null object id.
FailedObject: null [java.lang.String]
        at org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:898)
        at org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:880)
        at
org.apache.openjpa.kernel.DelegatingBroker.find(DelegatingBroker.java:223)
        at
org.apache.openjpa.persistence.EntityManagerImpl.find(EntityManagerImpl.java:477)

        at com.wrwlf.test.dao.DAOTest.main(DAOTest.java:38)

The entity with the following id is present in the database, the database
itself is very simple with two columns, id - VARCHAR(10) and text-
VARCHAR(50)

Could someone please help me to resolve this.

Thanks & regards

Sanjay Debnath

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message