java - Is there a way (e.g. an Eclipse plugin) to automatically generate a DTO from an Entity (JPA)? -


i plain forward dto generation tool either

  1. generate on fly (e.g. cglib - create class , dto object on fly)
  2. or eclipse plugin take entity , generate dto (user specify tree graph include, , non included, include foreign keys instead of related entities etc)

e.g. take this

@entity @table(name="my_entity") public class myentity {     @id @generatedvalue(strategy=generationtype.auto)     private long id;     private string name;      @manytoone     private relatedentity related;      public relatedentity getrelated(){           return related;      }      ... 

and generate :

@entity @table(name="my_entity") public class myentity imlpements myentitydto {     @id @generatedvalue(strategy=generationtype.auto)     private long id;     private string name;      @manytoone     private relatedentity related;      //overrides myentity interface, it's allowed narrow return type       public relatedentity getrelated(){           return related;      }      ...       //implements myentitydto respective interfaces       public long getrelatedid(){return related.getid();} 

and dto interface(s):

public interface myentitydto {      public string getid();     public string getname();     public long getrelatedid();     public relatedentitydto getrelated(); //relatedentity implements relatedentitydto      ... }  public interface relatedentitydto {     ...  } 

if don't want include children in graph, remove dto interface:

public interface myentitydto {      public string getid();     public string getname();     public long getrelatedid();      ... 

i'm sure there eclipse plugn , if not, challange write one, or explain why want not helpful (and provide alternative suggestion)

probably hibernate tools should doing this: http://hibernate.org/subprojects/tools.html


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -