0

i loaded two sql dumps into a spring boot application, one from 2020 and one from 2019. Now I want to compare one table called "tags" from the 2019 database with the "tags" table from the 2020 database. Is this possible by using the @Table / @Entity annotation?

@Table(name="tags",schema = "xyz")
@Entity
public class TagsEntityOld {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private Long version;
    private String description;
    private String name;
    private Timestamp createdOn;
    private String lastModifiedBy;
    private Timestamp lastModifiedOn;
    private String createdBy;

    public TagsEntityOld() {

    }

@Table(name="tags",schema = "xyz")
@Entity
public class TagsEntityNew {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private Long version;
    private String description;
    private String name;
    private Timestamp createdOn;
    private String lastModifiedBy;
    private Timestamp lastModifiedOn;
    private String createdBy;

    public TagsEntityNew() {

    }

  • btw the databases have different names – Tolga Hisir Nov 30 '20 at 14:00
  • Please clarify in your question what do you mean by Compare? You can create 2 Datasources, EntityManagers, Set 1 of the Datasources to @Primary. – Susan Mustafa Nov 30 '20 at 14:29
  • I just want to compare the values in table tags from datasource 2019 to the values in the table tags from datasource 2020, like x.equals(y). If i use the @Primary annotation, will spring automatically connect to the not primary set datasource after it connected to the primary datasource? – Tolga Hisir Nov 30 '20 at 15:01
  • You don't need two entities. Load two lists of "tags" from two different datasources and compare for equality. You can override the equals() method to suit your needs in the Entity class. – Tushar Nov 30 '20 at 15:12
  • @TolgaHisir Yes, Spring will autowire both. As long as you call Autowired and use the Datasource, it will be autowired – Susan Mustafa Nov 30 '20 at 15:22
  • Helpful link https://springframework.guru/how-to-configure-multiple-data-sources-in-a-spring-boot-application/ – Susan Mustafa Nov 30 '20 at 15:23
  • https://stackoverflow.com/questions/30337582/spring-boot-configure-and-use-two-datasources – Susan Mustafa Nov 30 '20 at 15:28

0 Answers0