karthik sai

Greenhorn
+ Follow
since Jan 06, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by karthik sai

HI,

I am using oracle 11g, JPA -Eclipse link implementation. The oracle has a table called currency

TABLE currency
Name Null? Type
----------------------------------------- -------- ----------------------------
CODE NOT NULL CHAR(3)
DESCRIPTION VARCHAR2(120)
CRT_ID VARCHAR2(10)
CRT_TIMESTAMP TIMESTAMP(6)

code + crt_timestamp is a composite primary key

Data in oracle
===========

COD DESCRIPTION CRT_ID CRT_TIMESTAMP
ind india system 05-AUG-12 01.47.02.250000 PM

Using JPA Named query, i am trying to retrieve the currency code with crt_timestamp in the query where clause.

The PO field for crt_timestamp is java.util.Date, i am unable to retrieve the result set since the the crt_timestamp format is not known.


The below code snippet i tried, but unable to retrieve the data

String dateFormat = "dd-MMM-yy HH.mm.ss.SSS aa"; //i see date format in oracle 11g
String date = "05-AUG-12 01.47.02.250000 PM";

DateFormat s = new SimpleDateFormat(dateFormat);
Date d = null;
try {
d = (Date)s.parse(date);
} catch (ParseException e) {
}

Timestamp ts = new Timestamp(d.getTime());

Currency resultBook = (Currency)em
.createQuery("select b from Currency b where crt_Timestamp="+ts)
.setMaxResults(1)
.getSingleResult();


Please could you shed some light on this and tell me if it will be done.

JPA Toplink - shared composite primary key id is not working using @EmbeddedId

This is the table script
CREATE TABLE Employee (
DEPARTMENT VARCHAR(255) NOT NULL,
STATE VARCHAR(255) NOT NULL,
my_salary BIGINT NOT NULL,
my_name VARCHAR(255), PRIMARY KEY (DEPARTMENT, STATE, my_salary))

The composite primary key is (DEPARTMENT, STATE, my_salary)

I have a AbstraceIdentiferPK.java which implements Serializable
@Column(name="my_salary")
protected long salary;

public long getSalary() {
return salary;
}

EmployeeIdPK extends AbstraceIdentiferPK
@Column(name="department")
protected String department;

@Column(name="state")
protected String state;

public EmployeeId(String department, String state, long salary) {
this.department = department;
this.state = state;
this.salary = salary;
}

In the Employee.java

@EmbeddedId
private EmployeeId id;

@Column(name="my_name")
private String name;

public Employee(EmployeeId id) {
this.id = id;
}

public EmployeeId getId() {
return id;
}

In the JPAMain.java

es.createEmployee(new EmployeeId("marketing", "MA", 1000000), "shekar");
es.createEmployee(new EmployeeId("marketing", "NY",800000), "Bill Clinton");
es.createEmployee(new EmployeeId("engineering", "MA",700000),"Angela Caicedo");

This is the peristed output

******** Table: EMPLOYEE *******
+--------------------------------+--------------------------------+--------------------------------+
| MY_NAME | DEPARTMENT | STATE |
+--------------------------------+--------------------------------+--------------------------------+
| Angela Caicedo | engineering | MA |
| shekar | marketing | MA |
| Bill Clinton | marketing | NY |
+--------------------------------+--------------------------------+--------------------------------+

The issue , the salary is not persisted in the database

Please let me know if i m missing anything.

Thanks for the reply, instead of putting into map , will put it in the coherence data grid, but the problem is fetching the number of record from the database using JDBC, since number of rows is 1,50000, need to fetch 500 records in order to avoid oracle connection time out issue
I have to cache the oracle table in java, the table has information such as user name,first name, last name and the size of the table is 1,50000 rows. We need to use JDBC to query the table for 500 records and subsequently firing next 500 record for the same. We are planning to use java Hashmap , where the key would be user name and the value would be the Value Object say UserInfoVO. The UserInfoVO will have all the user information. It would be like Map<String, UserInfoVO>. Please suggest us the pseudo code for fetching 500 records and next 500 record until the entire table is cached in the HashMap.