Issue Details (XML | Word | Printable)

Key: OPENJPA-132
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Unassigned
Reporter: Michael Dick
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
OpenJPA

java.lang.NoSuchMethodError for entity with ID of type java.sql.Date

Created: 07/Feb/07 10:40 PM   Updated: 17/Apr/07 06:38 PM
Return to search
Component/s: kernel
Affects Version/s: None
Fix Version/s: 0.9.7

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works OpenJPA-132.patch.txt 2007-03-19 03:59 PM Michael Dick 25 kB

Resolution Date: 20/Mar/07 07:02 PM


 Description  « Hide
Opening JIRA report to track the following problem (posted to development forum http://www.nabble.com/Exception-when-using-java.sql.Date-as-an-id-tf3189597.html)

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?


Responses from Patrick and Craig follow. The consensus so far is to provide ID separate classes for java.sql.Date and java.util.Date.

It looks like we either need a separate type for java.sql.Date (and
presumably java.sql.Timestamp), or we need to change the logic to accept
a getId() method that returns a type that is assignable from the id
field's type.

-Patrick

It's probably cleaner if we have separate classes for the different
types. That is, have the getId method in the new
org.apache.openjpa.util.SQLDateId return the proper type
(java.sql.Date). After all, java.sql.{Date, Time, Timestamp} are not
really the same as java.util.Date.

-Craig

FTR, I think that I prefer separate classes as well; it's clearer, and
avoids any ambiguity with other subclasses in the future.

-Patrick

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Repository Revision Date User Message
ASF #520522 Tue Mar 20 19:00:38 UTC 2007 awhite OPENJPA-132 : Fix bugs with using a field of type java.sql.Date/Time/Timestamp
as a single-field identity primary key. Replaced "generationtype" test package
with "identity" test package and moved old identity generation tests to new
package, along with new test for java.sql.Date id fields.
Files Changed
ADD /incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestGenerationType.java (from /incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestGenerationType.java)
ADD /incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity
ADD /incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/IdentityGenerationType.java (from /incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/IdentityGenerationType.java)
DEL /incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestGenerationType.java
MODIFY /incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
DEL /incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/IdentityGenerationType.java
MODIFY /incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ApplicationIds.java