I've a JPA 2.0 entity, with a java.util.Date field mapped to a DATE column in Oracle. The field intended to represent just the time part, so I added the @Temporal(TemporalType.TIME) annotation.
I'm using JBoss AS 6.0.0.
All is fine when I read the entity because the field contains a java.sql.Time instance.
Insteand when I persist the entity to the DB I can insert a value containing also a date part and it's written to the DB.
I was expecting that the date part was stripped away from the value written to the DB or that a validation would throw an exception, but this isn't the case.
The think get worse when the Date field is in the key (and this is my case) because if I try to remove the entity nothing happens. For example:
Code:
Date key = new Date(); // Date and time
MyEntity ent = new MyEntity();
ent.setTime(key);
ent.set....;
em.persist(ent); // Date and time written in the DB column
em.flush();
em.clear();
ent = query.getSingleResult(); // a query loading the entity persisted above
System.out.println(em.getTime()); // Just the time part
em.remove(ent);
// The row is still in the db
I think this happens because the DELETE statement use just the time part in the condition.
Is this the right behaviour according to the specification? Have I to validate the value manually before setting it into my entity the entity?
Thanks,
Andrea