Doesn't seem like anything has happened here. I've ended up referencing each 
indiviudal entity-class, though it's a little more work.

However if you have lot's of entity beans, and you need an efficient way to 
find them and create the xml-references for persitence.xml - try this little 
piece of code:


  | import java.io.File;
  | import java.lang.annotation.Annotation;
  | 
  | /**
  |  * Tool to scan for all entity beans in a package and generate 
persistence.xml class entries
  |  * @author peter
  |  *
  |  */
  | public class GenPersistArchives {
  |  String basePath;
  |  String persistClasses = "";
  |  
  |  public GenPersistArchives(String basePath)
  |  {
  |   this.basePath = basePath;
  |   File dir = new File(ClassLoader.getSystemResource(basePath).getPath());
  |   scan(dir);
  |   System.out.println(persistClasses);
  |  }
  |  
  |     static final String translateToJavaPath(String uri)
  |     {
  |         // Translate into classname, and also handle subclasses
  |         String className = uri.replace(".class","");
  |         if(className.indexOf("$1")>0)
  |             className = className.substring(0,className.indexOf("$1"));
  |         className = className.replace("/",".");
  |         return className;
  |     }
  |  private void scan(File dir)
  |  {
  |   for(File file : dir.listFiles())
  |   {
  |    if(file.isDirectory())
  |     scan(file);
  |    else
  |    {
  |     String relativePath = file.getPath();
  |     relativePath = relativePath.substring(relativePath.indexOf(basePath));
  |     String className = translateToJavaPath(relativePath);
  |     try
  |     {
  |      Class cls = Class.forName(className);
  |      for(Annotation ann : cls.getAnnotations())
  |      {
  |       
if(ann.annotationType().getName().equals(javax.persistence.Entity.class.getName()))
  |       {
  |        persistClasses+="<class>"+className+"</class>\n";
  |       }
  |      }
  |      
  |     } catch(Exception e)
  |     {
  |      e.printStackTrace();
  |     }
  |     
  |    }
  |   }
  |  }
  |  /**
  |   * @param args
  |   */
  |  public static void main(String[] args) {
  |   // Package to scan
  |   new GenPersistArchives("com/lightminds/cms/ejb3");
  |   
  |  }
  | }
  | 

Good luck,

Peter

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3909493#3909493

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3909493


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
JBoss-user mailing list
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to