102 words

Query all objects that implements a given interface - is that possible?

#1
2014-12-22 15:45

Hi,

I am trying query one of my DB - for all object types that implement a given interface.

    TypedQuery<Signal_Interface> query =
        em.createQuery("SELECT bk FROM Signal_Interface bk", Signal_Interface.class);

I got the following error. 

I am not sure it is possible to do it - Any suggestion would be appreciated.

Regards,

EKK

Exception in thread "main" [ObjectDB 2.5.1_05] javax.persistence.PersistenceException
Attempt to define unbound variable ('bk') of type Signals.Signal_Interface (error 737)
at com.objectdb.jpa.JpaQuery.getResultList(JpaQuery.java:695)
at DB.DB_for_Signals$ActualDB.ALL(DB_for_Signals.java:105)
at DB.DB_for_Signals.ALL(DB_for_Signals.java:29)
at Signals.Signal_Base.loadAllSignals(Signal_Base.java:170)
at Signals.Signal_Base.main(Signal_Base.java:176)
Caused by: com.objectdb.o.UserException: Attempt to define unbound variable ('bk') of type Signals.Signal_Interface
EKK
EKK's picture
Joined on 2013-03-05
User Post #11
#2
2014-12-22 16:35

Try:

    TypedQuery<Signal_Interface> query =
        em.createQuery("SELECT bk FROM Object bk WHERE bk instanceof Signal_Interface",
            Signal_Interface.class);
ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #2,102
#3
2015-01-03 08:31

It worked - thanks a lot

EKK
EKK's picture
Joined on 2013-03-05
User Post #13

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Attachments:
Maximum file size: 32 MB
Cancel