Results 1 to 6 of 6

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

  1. #1

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    Quote 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.
    Ben Alex
    Project Founder, Spring UAA, Spring Roo and Spring Security

  3. #3

    Default

    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

  4. #4

    Default

    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

  5. #5
    Join Date
    Mar 2008
    Location
    Sydney, AU
    Posts
    974

    Default

    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.
    Stefan Schmidt
    Software Engineer, Spring Roo
    SpringSource - a division of VMware
    twitter @schmidtstefan

  6. #6

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •