Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Date as primary key  RSS feed

 
Ng Jeffrey
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a cmp with compound primary key. As one one of the primary key is a date data type. It always throws out "Error: javax.ejb.NoSuchEntityException:Entity not found: primary key .....". I am writing a program for a legacy system in which the database schema cannot be change.

Has anyone encountered this issue and have a solution or alternatives?

thanks in advance
 
Slava Imeshev
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ng,

What is the app server?
What is the DB sever?
Could you post the primary key class and database table scheme for the bean?
 
BoonHock Ng
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I found the solution. As my database is sybase, the following is posted at this URL

http://java.sun.com/j2ee/1.4/docs/devguide/dgcmp.html

Date and Time Fields as CMP Field Types
If a CMP field type is a Java date or time type (java.util.Date, java.sql.Date, java.sql.Time, java.sql.Timestamp), make sure that the field value exactly matches the value in the database.

For example, the following code uses a java.sql.Date type as a primary key field:

java.sql.Date myDate = new java.sql.Date(System.currentTimeMillis())
beanHome.create(myDate, ...);

This code results in only the year, month, and date portion of the field value being stored in the database. Later on if the client tries to find this bean by primary key as follows:

myBean = beanHome.findByPrimaryKey(myDate);

the bean is not found in the database because the value does not match the one that is stored in the database.

Similar problems can happen if the database truncates the timestamp value while storing it, or if a custom query has a date or time value comparison in its WHERE clause.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!