-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java.lang.ClassCastException: org.eclipse.persistence.internal.platform.database.oracle.TIMESTAMPTZWrapper cannot be cast to oracle.sql.TIMESTAMPTZ #23
Comments
Can you try to remove or comment out the |
I unfortunately still get the same error... |
What operation do you perform when this happens? Are you using criteria API? |
The problem is |
I am executing a |
That's really interesting, the tests have no dependency on
|
If I set |
At this point we have established that it's a bug in EclipseLink so we should get in contact with them and report a bug. They should also be able to recommend the best work around. Coming up with a patch should be doable but a reproducer and test may be more work, I don't know what infrastructure they have in place. In your typed query do you pass the |
I will let in on your table 😄 There are two |
Maybe useful for somebody, here is my extended Platform class, which you can set as import com.github.marschall.threeten.jpa.oracle.impl.TimestamptzConverter;
import oracle.sql.TIMESTAMPTZ;
import org.eclipse.persistence.internal.helper.ClassConstants;
import org.eclipse.persistence.internal.sessions.AbstractSession;
import org.eclipse.persistence.platform.database.oracle.Oracle12Platform;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.ZonedDateTime;
import java.util.GregorianCalendar;
public class Oracle12WrapperlessPlatform extends Oracle12Platform {
@Override
public Object getTIMESTAMPTZFromResultSet(final ResultSet resultSet,
final int columnNumber,
final int type,
final AbstractSession session) throws SQLException {
return resultSet.getObject(columnNumber);
}
@Override
public Object convertObject(final Object sourceObject, final Class javaClass) {
Object valueToConvert = sourceObject;
if (sourceObject instanceof TIMESTAMPTZ) {
final ZonedDateTime zonedDateTime = TimestamptzConverter.timestamptzToZonedDateTime((TIMESTAMPTZ) valueToConvert);
if (javaClass == ClassConstants.CALENDAR || javaClass == ClassConstants.GREGORIAN_CALENDAR) {
valueToConvert = GregorianCalendar.from(zonedDateTime);
} else {
valueToConvert = new Timestamp(zonedDateTime.toInstant().getEpochSecond() * 1000L);
}
}
return super.convertObject(valueToConvert, javaClass);
}
} |
I did some additional testing and the issue is limited to criteria API but reading in general. When I use <property name="eclipselink.target-database" value="Oracle"/> I can no longer reproduce the issue. I don't know what other features you use so I don't know if this is an option for you. |
I filed bug 511999, let's see where it goes from here. |
Thanks for your effort. I will follow the opened bug. |
Better tests for #23 and work arounds
@maksymgendin I did some additional testing and simply calling My platforms look like this: |
@marschall I think this happens if you are mixing usage of ZonedDateTime AND Calendar in your entities. The exception then appears if you are reading the entity with Calendar field. |
@maksymgendin is there a specific reason why you're doing that or did you simply for testing or migration purposes simply start with just one column? |
@marschall We unfortunately have some older shared entity classes with Calendar fields. At some point we will migrate them to ZonedDateTime. |
@maksymgendin do you use |
|
I now understand why you had to implement |
@maksymgendin the following path in your fix new Timestamp(zonedDateTime.toInstant().getEpochSecond() * 1000L); is limited to second precision, Timestamp.valueOf(zonedDateTime.withZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime()); which should give you nanosecond precision. The case is a bit theoretical though, mapping |
@marschall You're so right! Thank you very much for that point. You may have saved me from future headaches with finding bugs :) |
When I use the fixed approach, the Converter cannot be auto applied anymore, as the following Exception is thrown:
When I annotate the field with |
@frl7082 unless you have exactly the same setup and issue as OP would you mind opening a separate issue instead? |
nevermind, was an error in my project setup |
I'm am using org.eclipse.persistence:eclipselink:2.6.4 with com.oracle.jdbc:ojdbc7:12.1.0.2 and this is my
TIMESTAMP WITH TIMEZONE
entity field:On querying the database I get:
Do you have any ideas how can I fix this without extending the EclipseLink Oracle-specific Platform class and overwriting the methods which wrap
TIMESTAMPTZ
inTIMESTAMPTZWrapper
?The text was updated successfully, but these errors were encountered: