Announcement Announcement Module
Collapse
No announcement yet.
roo generates Column(name = "id")for a enity that maps to a table that has no id col Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • roo generates Column(name = "id")for a enity that maps to a table that has no id col

    I have a enity, that maps to a table that has no Column name called "id".

    When ever I start roo it automatically regenerates my _roo_entity.aj and _roo_ToString.aj files.

    and includes

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Long AgreementEntity.id;

    Since the table in question does not have a id table this will cause my build to fail.

    Also since we have a lot of tables to map we created a JPA project and reverse engineered a number of entitys.

    This worked but when we added the

    @RooJavaBean
    @RooToString
    @RooEntity

    It not only generated the Ids but also for some files generated them as

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "_id")
    private Long AgreementEntity.id;

    And none of our tables have a Column name "_id".

    It might be confusion over the @id, in the first instance we have

    @Id
    @Column(name = "agreement_id")
    private Integer agreementId;

    Will this force roo to generate

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "_id")
    private Long AgreementEntity.id;

    In the second case I am not sure, it might be to do with mapping

    fileA Has more than one FileB
    Id fileAId

    When generated fileA

    has @Column(name = "id")

    When generated fileB

    has @Column(name = "_id")


    Anyone else seen this problem.

    Thanks for any help I want to try an stick with the reverse engineer mapping has its a good easy tool to use.

  • #2
    Originally posted by tonycav View Post
    Code:
    @Id    
        @GeneratedValue(strategy = GenerationType.AUTO)    
        @Column(name = "agreement_id")    
        private Long id;
    If you add the above to your .java file, together with a public getter and setter for the field, Roo will automatically take your manually-defined identifier as authoritative and will no longer introduce an identifier via an ITD. I think that will solve your problem.

    Comment


    • #3
      Thanks will try it tomorrow. And let you know the resault. I dare say it will also solve the problem of the reverse engineered entitys, where entityA id is mapped to entityAId in entityB, but for entityB id is genearted as column name _id

      Comment


      • #4
        Hi in my code I put AgreementEntity.java

        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name = "agreement_id")
        protected Integer agreementId;


        In my roo_entity.aj roo generated:

        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name = "agreement_id")
        protected Integer agreementId;


        Remove @id

        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name = "id")
        private Long AgreementEntity.id;

        There must be a way to stop roo from generating id

        Thanks for any help

        Comment


        • #5
          Does JPA actually allow the creation of @Entity classes which have no identifier at all? If you have a unique column which serves as identifier to your entity you should map that to a field in your entity.

          Comment


          • #6
            Hi Stefan

            I think I see what you mean

            for

            @Id
            @GeneratedValue(strategy = GenerationType.AUTO)
            @Column(name = "agreement_id")
            protected Integer agreementId;


            I need to add

            @Id
            @GeneratedValue(strategy = GenerationType.AUTO)
            @Column(name = "agreement_id" unique="true")
            protected Integer agreementId;

            I will see if this works on Monday thanks Tony

            Comment

            Working...
            X