Uploaded image for project: 'Forge'
  1. Forge
  2. FORGE-572

Forge scaffold faces creates view beans with Id always Long against user-generated Entities

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor Minor
    • 1.3.0.Final
    • 1.0.2.Final
    • Scaffold
    • Hide
      • Create or generate a JPA Entity with an @Id of a type other than Long (Integer and String are known to cause this issue, other types are merely suspected).
      • Launch forge, set up scaffold for the project.
      • Run: scaffold from-entity ~.domain.* --overwrite
      • Examine output view beans, or deploy app and attempt to CRUD an Entity of the above kind.
      • Result: cast failure or lookup failure as Long is not translatable to other types in many cases.
      Show
      Create or generate a JPA Entity with an @Id of a type other than Long (Integer and String are known to cause this issue, other types are merely suspected). Launch forge, set up scaffold for the project. Run: scaffold from-entity ~.domain.* --overwrite Examine output view beans, or deploy app and attempt to CRUD an Entity of the above kind. Result: cast failure or lookup failure as Long is not translatable to other types in many cases.

      When running:

      scaffold from-entity ~.domain.* --overwrite

      The generated view Bean will always use an id field as a long, even if the entity uses a different type for the @Id. For instance, this code, in an Entity class called ValMealtype:

      @Id
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      @Column(unique=true, nullable=false, length=20)
      private String meal;

      Generates, in ValMealtypeBean:

      private Long id;

      <-- associated gettters and setters -->

      And, later in the class:

      return ValMealtypeBean.this.entityManager.find(ValMealtype.class, Long.valueOf(value));

      That line in particular doesn't work at all, of course, since a Long can't be parsed out of a non-numeric String. I suppose I could name my meals with hex digits . . . CAFE . . . BEEF . . . but sadly, Chicken isn't going to fly.

      Basically, scaffold probably needs to look at the type of @Id in the entity and use that to set the id field type in the generated bean.

      As this is reported against a non-current release, I understand it may be fixed already. In this case, a new Beta of JBDS 5 is probably in order, as that's where I'm seeing this issue.

              vineet.reynolds_jira Vineet Reynolds (Inactive)
              wdinyes_jira Will Dinyes (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: