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

#1

I am using JPA programaticaly..ie 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) {
      em.getMetamodel()
        .managedType(x);
 }

 

Thanks for any help

 

#2

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
#3

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.

#4

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
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login