JPA: how to make an object from the columns of several tables (do not save the object for table layout)

I have two objects:

@Entity
@Table(name="TableA")
public class TableA {
     @Id
     @Column(name="id")
     long id;

     @Column(name="tableB_id")
     long tbId;

     @Column(name="column1", table="TableB")
     String tbColumn1; 
}

@Entity
@Table(name="TableB")
public class TableB {
     @Id
     @Column(name="id")
     long id;

     @Column(name="column1")
     String column1; 
}

TableA has a tbId foreign key for TableB.id. And TableB has a column named "column1", now I want to get "column1" in the TableA object by some kind of join. How should I go to JPA? This is not OneToOne, because I do not want to connect the entire TableB object to TableA.

+5
source share
1 answer

If you want to group columns within a single read-only object, I offer you two ways:

  • Creating a VIEW database and displaying it as an object.
  • , .

ObjectDB . :

JPA JPQL . SELECT , Object [].

+10

All Articles