Hi Fiorenzo,
You can get a list of entity classes from an EntityManager. Then add code to
scan the @NamedQuery and @NamedQueries({ ... }) annotations on those classes
and make a list of NamedQuery names.
Like this:
| // Get all entity classes
| org.hibernate.SessionFactory sf = ((org.jboss.ejb3.entity.HibernateSession)
em).getHibernateSession().getSessionFactory();
| Map<?,?> allClassMetadata = sf.getAllClassMetadata();
| List<String> queries = new ArrayList<String>();
| for (Object value: allClassMetadata.values()) {
| EntityPersister ep = (EntityPersister) value;
| Class<?> entityClass =
ep.getClassMetadata().getMappedClass(EntityMode.POJO);
| NamedQuery nqAnno = entityClass.getAnnotation(NamedQuery.class);
| if(nqAnno != null)
| queries.add(nqAnno.name());
| NamedQueries nqsAnno = entityClass.getAnnotation(NamedQueries.class);
| if(nqsAnno != null) {
| for(NamedQuery q: nqsAnno.value())
| queries.add(q.name());
| }
| }
|
I haven't tested this code.
Good luck.
Regards,
Matt
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4181054#4181054
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4181054
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user