3 Replies Latest reply on Oct 4, 2013 9:53 AM by maxandersen

    foreign key columns along with associations with hibernate reverse engineering

    surkov

      Hi,

       

      I want to generate foreign key columns along with associations ManyToOne for every association

      for example:


      1. @ManyToOne(fetch = FetchType.EAGER)

        @JoinColumn(name = "REF_DOCUMENTS_STATUS_FK", nullable = false)

        private RefDocumentsStatus refDocumentsStatus;

       

      and

       

      2. @Column(name = "DOCUMENTS_FK", unique = true, nullable = false, scale = 0 , updatable = false, insertable = false )

        private Long documentFk;

       

      now i can get either the first or the second variant (with help of MyReverseEngineeringStrategy excludeForeignKeyAsCollection)

        • 1. Re: foreign key columns along with associations with hibernate reverse engineering
          maxandersen

          You need to provide a bit more details.

           

          What are you seeing today and what is it you expect ?

           

          What table layout are you using ?

          • 2. Re: foreign key columns along with associations with hibernate reverse engineering
            surkov

            Sorry i it was a mistake in JoinColumn


            My tables are:


            create table document (id int);

             

            create table document_status(

            id int,

            documents_fk int);

            alter table document_status add constraint ttt foreign key (documents_fk) references document (id);

             

            now after generation i have in the DocumentStatus class

              @ManyToOne(fetch = FetchType.LAZY)

              @JoinColumn(name = "DOCUMENTS_FK", nullable = false)

              private Document document;


            or if i use MyReverseEngineeringStrategy excludeForeignKeyAsCollection

            i will have simple field without any association

             

            @Column(name = "DOCUMENTS_FK", nullable = false)

              private Long documentFk;

             

            but my goal is to get both of them in DocumentStatus class

            it is convenient in some cases

             

            @ManyToOne(fetch = FetchType.LAZY)

              @JoinColumn(name = "DOCUMENTS_FK", nullable = false)

              private Document document;

            and

            @Column(name = "DOCUMENTS_FK", nullable = false, updatable = false, insertable = false)

              private Long documentFk;

             

             


            • 3. Re: foreign key columns along with associations with hibernate reverse engineering
              maxandersen

              You can adjust the .ftl templates to get this if you want.

               

              But i'm pretty sure one of the sides will just be ignored by JPA though.