ClassCastException on SELECT NEW ... after UPDATE over Java RMI



we are using ObjectDB 2.5.4_04 on Linux. Our application, which uses ObjectDb as a DB, exposes a Java RMI interface which allows remote RMI clients to run JPQL queries on the DB.

The application internally runs SELECT NEW ... queries. For example:

SELECT NEW com.arunta.base.db.FileNameDTO(, r.fileName) FROM RecordingMetaData AS r WHERE ...

A remote RMI client runs SELECT (but not SELECT NEW ...) and UPDATE JPQL queries on the DB via the RMI interface. What we noticed is that once we UPDATE a record from the client (via the RMI interface), all SELECT NEW ... queries, which the applications runs internally, start to fail with ClassCastException. The same exception is thrown by your DB Explorer tool when trying the same, or similar, SELECT NEW ... query:

Exception in thread "AWT-EventQueue-0" [ObjectDB 2.5.4_04] javax.persistence.PersistenceException              
Failed to build result of type 'NEW com.arunta.base.db.FileNameDTO(, r.fileName)' (error 783)              
        at java.awt.AWTEventMulticaster.mouseMoved(                               
        at java.awt.Component.processMouseMotionEvent(                                     
        at javax.swing.JComponent.processMouseMotionEvent(                                
        at java.awt.Component.processEvent(                                                
        at java.awt.Container.processEvent(                                                
        at java.awt.Component.dispatchEventImpl(                                           
        at java.awt.Container.dispatchEventImpl(                                           
        at java.awt.Component.dispatchEvent(                                               
        at java.awt.LightweightDispatcher.retargetMouseEvent(                              
        at java.awt.LightweightDispatcher.processMouseEvent(                               
        at java.awt.LightweightDispatcher.dispatchEvent(                                   
        at java.awt.Container.dispatchEventImpl(                                           
        at java.awt.Window.dispatchEventImpl(                                                 
        at java.awt.Component.dispatchEvent(                                               
        at java.awt.EventQueue.dispatchEventImpl(                                          
        at java.awt.EventQueue.access$200(                                                 
        at java.awt.EventQueue$                                                      
        at java.awt.EventQueue$                                                      
        at Method)                                          
        at java.awt.EventQueue$                                                      
        at java.awt.EventQueue$                                                      
        at Method)                                          
        at java.awt.EventQueue.dispatchEvent(                                              
        at java.awt.EventDispatchThread.pumpOneEventForFilters(                   
        at java.awt.EventDispatchThread.pumpEventsForFilter(                      
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(                   
        at java.awt.EventDispatchThread.pumpEvents(                               
        at java.awt.EventDispatchThread.pumpEvents(                               
Caused by: com.objectdb.o.UserException: Failed to build result of type 'NEW com.arunta.base.db.FileNameDTO(, r.fileName)'                                                                                                 
        at com.objectdb.o.MSG.d(                                                                   
        at com.objectdb.o.ORB.l(                                                                  
        at com.objectdb.o.RSL.r(                                                                  
        at com.objectdb.o.RSL.get(                                                                
        ... 44 more                                                                                            
Caused by: java.lang.IllegalArgumentException: java.lang.ClassCastException@13a7f4bd                           
        at sun.reflect.GeneratedConstructorAccessor2.newInstance(Unknown Source)                               
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
        at java.lang.reflect.Constructor.newInstance(                                     
        at com.objectdb.o.ORB.l(                                                                  
        ... 46 more

For your information the is (simple bean):

public class FileNameDTO {

    private Long id;
    private String fileName;

    public FileNameDTO(Long id, String fileName) { = id;
        this.fileName = fileName;

    public Long getId() {
        return id;

    public void setId(Long id) { = id;

    public String getFileName() {
        return fileName;

    public void setFileName(String fileName) {
        this.fileName = fileName;


The attached DB file has 3 records which were updateted by a remote client (over RMI). They have IDs 9766, 9890 and 9897. These records cause all SELECT NEW ... type queries, which run internally, to fail with the ClassCastException.

Other SELECT queries (i.e. non SELECT NEW ... quereis) work fine inside the application and from remote clients via RMI after the update. For example SELECT COUNT(*) ..., or SELECT r FROM ... all work fine.


DB Doctor does not fix the problem.

We need guidance on how to debug and fix the problem.

Thank you











The value of the id field in entity object RecordingMetaData#9897 is Integer rather than Long.

Therefore, if the constructor of FileNameDTO expects a Long value there is no match.

As a workaround you can change the query to:

SELECT NEW com.arunta.base.db.FileNameDTO((long), r.fileName)
FROM RecordingMetaData AS r ...

so a casting should solve the mismatch.

According to your report, it may be possible to set a value of a different type in an UPDATE query. Check your UPDATE queries and see if you can specify new values as long explicitly rather than as int to avoid this mismatch.

ObjectDB Support

This is a bit confusing. We do not understand how the id field in RecordingMetaData can be Integer when it is defined as Long:

public class RecordingMetaData {

    private Long id;
    private Long version;

Just in case we introduced problems in the original attached DB, we are attaching here two DB files which were produced under controlled condition as follows:

1. We started the application without a DB. It creates a new DB file and then adds 5 records in it. The DB file is in All works well with this DB file. We can run SELECT NEW ... queries both in the application and with DB Explorer.

2. Then we run the following update query from the remote client over RMI (extract from the application log including information from log4j):

INFO [RMI TCP Connection(7)-] ( - Remote user emil executing DB update:                                                                                                          
UPDATE RecordingMetaData AS r SET r.notes='#%# Emil~FE~FF~00~27s note' WHERE IN (1)

The DB file after the query is in As you can see the update completes Ok. We see the problem with SELECT NEW ... queries after this update both in the application and with DB Explorer. As a matter of fact any update causes the problem. The above is just an example.


Each of the DB files shows the id field for all 5 records as Long. We do not update the id field in any way. Hence our confusion on how it can be Integer.

Thank you for your assistance.




If you run the following query on both databases you can see the difference:

select from RecordingMetaData r

For object #1 the id is Integer rather than Long in the second database.

You can fix the database with the following query that changes it back to Long.

UPDATE RecordingMetaData AS r SET r.notes=r.notes WHERE IN (1L)

Obviously this is a bug. ObjectDB supports dynamic types (in order to support dynamic type languages in the future), but this is currently not in use, and anyway, the value from the WHERE clause should not replace the existing value.

We will fix the bug soon. But meanwhile as a workaround, make sure that the type in the IN expression matches the type of the field, and it should work.

ObjectDB Support

Thank you. We look forward to the release that contains a fix for this problem.



Build 2.5.5_06 includes a fix for this issue. Thank you for your report.

ObjectDB Support

I can confirm that the issue does not exist in 2.5.5_14. Thank you.


This issue has re-surfaced in 2.6.1_05. See attached screen capture.

The type of the IDs is changed to Integer from Long during queries.




It could be another cause of the same issue.

We have a simple test code from your previous report, but we do not have the test database:

public final class T1401 {

    public static void main(String[] args)  {

        EntityManagerFactory emf = Persistence.createEntityManagerFactory(
        EntityManager em = emf.createEntityManager();

        Query query = em.createQuery(
            "SELECT NEW com.arunta.base.db.FileNameDTO(, r.fileName) " +
            "FROM RecordingMetaData AS r");
        List resultList = query.getResultList();

Could you please provide an up to date database and query that can demonstrate this issue?


ObjectDB Support