0

I have JPA Entity

@Entity
@Table(name = "PEOPLES_TABLE")
public class peoplesTable {
    @Id
    @Column(name = "ID", nullable = false, length = 36)
    private String id;

    @Column(name = "Name", nullable = false, length = 255)
    private String name;

    @Column(name = "Soname", nullable = false, length = 255)
    private String soname;
}

And I have class

*public class Table {
  private String name;
  private List<Column> columns;

  public Table(String name, List<Column> columns){
  this.name = name;
  this.columns = columns;
  }
}*

Also I have class Column.

public class Column {

  private String name;
  private String type;
  private String length;
  private String defaultValue;
  private String nullable;
  private String constraint;
  private String commentOnColumn;
  public Columnn(){
      <-Constructor->
  }
}

Tell me the best way to map my Entity to object Table. I try to do it with javaParser, but it was a fiasco =(

  • You can use your entity as a class, dont need parse... or you use a for each and populate other class –  Feb 20 '18 at 14:28
  • Yes, I have a lot of .java files with entities, and I need to map theirs to class Table – Starcev Misha Feb 20 '18 at 14:31
  • It'll be hard to get answers as we have no clue why you'd duplicate the JPA annotations or need this information when you are the one providing it on your object model through annotations. If you can't access it from your JPA provider after it has parsed it, you would have to write your own annotation processor to go through your entities and build your table/column objects - more than a few JPA implementations are open source and can be used to get you started. – Chris Feb 20 '18 at 15:15
  • If what you want to do is get meta informations about an sql table and its columns then you can just do it using plain jdbc like shown [here](https://stackoverflow.com/a/12599476/1113392) or using jpa by following the steps shown [here](https://stackoverflow.com/a/31241758/1113392). Other than that it's unclear what you are asking. – A4L Feb 20 '18 at 15:34
  • @Chriss, I need To store information about my table in object of class Table. What you can say about JPA provider? – Starcev Misha Feb 21 '18 at 13:51

0 Answers0