How to define Default Entity Listeners without persistence.xml and orm.xml


I am using JPA without xml file, and i would like to define Default Entity Listeners.

How to do ?

Here my init code:

Properties config = new Properties();
config.put("javax.persistence.provider", "com.objectdb.jpa.Provider");
config.put("javax.persistence.jdbc.url", "objectdb://localhost/my.odb");
config.put("javax.persistence.jdbc.user", "admin");
config.put("javax.persistence.jdbc.password", "admin");

EntityManagerFactory factory = Persistence.createEntityManagerFactory("$objectdb/db/points.odb", config);    EntityManager em = factory.createEntityManager();
    for (Class< ? > x : annotatedClasses) {


Thanks for any help



Defining default listeners is one of the few things that currently require XML metadata.

You cannot define default listeners using annotations (at least in JPA 2.0).

ObjectDB Support

Is there a way using em.getDelegate() and then using objectdb api ?

I would like to do specifics actions when my objects are persisted, without using XML, and without defining listeners for each classe.


If you use JPA you will need either listeners or callback methods as explained in chapter 3 of the manual. You may also register listener using the JDO API, which is not documented but supported by ObjectDB.

ObjectDB Support