openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Dick" <michael.d.d...@gmail.com>
Subject Exception when using java.sql.Date as an id
Date Wed, 07 Feb 2007 20:56:32 GMT
Hi,

I'm getting the following exception when I try to fetch an entity with a
java.sql.Date as the id :

java.lang.NoSuchMethodError: org.apache.openjpa.util.DateId.getId
()Ljava/sql/Date;
    at mikedd.entities.SqlDatePK.pcCopyKeyFieldsFromObjectId (SqlDatePK.java
)
    at mikedd.entities.SqlDatePK.pcNewInstance(SqlDatePK.java)
    at org.apache.openjpa.enhance.PCRegistry.newInstance(PCRegistry.java
:118)
    at org.apache.openjpa.kernel.StateManagerImpl.initialize (
StateManagerImpl.java:247)
    at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initializeState(
JDBCStoreManager.java:327)
    at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initialize(
JDBCStoreManager.java:252)
    at org.apache.openjpa.kernel.DelegatingStoreManager.initialize(
DelegatingStoreManager.java:108)
    at org.apache.openjpa.kernel.ROPStoreManager.initialize(
ROPStoreManager.java:54)
    at org.apache.openjpa.kernel.BrokerImpl.initialize (BrokerImpl.java:868)
    at org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:826)
    at org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:743)
    at org.apache.openjpa.kernel.DelegatingBroker.find (
DelegatingBroker.java:169)
    at org.apache.openjpa.persistence.EntityManagerImpl.find(
EntityManagerImpl.java:346)
    at mikedd.tests.TestSqlDateId.testFindAfterClear(TestSqlDateId.java:25)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke (Method.java:585)
    at junit.framework.TestCase.runTest(TestCase.java:154)
    . . .

It's coming from the generated bytecode which expects there to be a getId
method that returns the same type of the Id, however java.sql.Date is using
the same ID class as java.util.Date. Do we need a separate class for
java.sql.Date?

Here's the entity and testcase that I'm running (in case I missed something
along the way)

Entity :
import java.sql.Date;

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

@Entity
public class SqlDatePK {

    @Id
    private Date id;
    private String name;

    . . .
}

Testcase :
public void testFindAfterClear() {
        SqlDatePK sql;

        EntityManager em = _emf.createEntityManager();

        long ms = 101010;  // arbitrary date.
        java.sql.Date date = new java.sql.Date(ms);

        em.getTransaction().begin();

        sql = new SqlDatePK();
        sql.setId(date);
        em.persist(sql);

        em.getTransaction().commit();

        em.clear();
        sql = null;
        sql = em.find(SqlDatePK.class, date);

     . . .
}

Thanks in advance,
-- 
-Michael Dick

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