IBM Support

PK81605: UML to JPA transformation creates named queries based on SQL nam es rather than Java names

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • Environment:
    
    Microsoft WIndows XP
    IBM Rational Software Architect for Websphere v. 7.5.1
    IBM WEbsphere Application Server 7.0.0.1
    
    Problem description:
    
    In the UML to JPA transformation:
    
    When the 'name' property of the ??Entity?? stereotype is used
    and/or the 'name' property of the ??Column?? stereoptype is used
    
    the generated namedqueries use the Table/Column names instead of
     the Class/Attribute names
    
    The code compiles and can be deployed byt fails at runtime with
    errors like:
    
    An error occurred while parsing the query filter 'select obj fro
    m PRODUKT where obj.ID = :ID'. Error message: The name 'PRODUKT'
     is not a recognized entity or identifier. Perhaps you meant Pro
    dukt, which is a close match. Known entity names: [Produkt]
    
    Steps to Reproduce:
    
    1.Create a model with UML Class Produkt stereotyped with ??Entit
    y?? from the UML to JPA Profile
    2. add one column stereotyped as ??Id??
    
    3. The generated code is:
    
    @Entity
    @NamedQuery(name = 'Produkt.findByid', query = 'select obj from
    Produkt where obj.id = :id')
    public class Produkt implements Serializable {
    
     @Id
     private Object id;
    
    4. override the automatically generated table name with the 'nam
    e' attribute of the ??Enity?? stereotype, which by itself is sup
    posed to generate the @Table annotation so that the generated DD
    L will contain
    
    create table PRODUKT
    
    instead of
    
    create table Produkt
    
    5. This modification of the model results in the following gener
    ated code:
    
    @Entity
    @Table(name = 'PRODUKT')
    @NamedQuery(name = 'PRODUKT.findByid', query = 'select obj from
    PRODUKT where obj.id = :id')
    public class Produkt implements Serializable {
    
     @Id
     private Object id;
    
    
    6. Also override the generated column name using the ??column??
    stereotype and its 'name' property, set to ID:
    
    @Entity
    @Table(name = 'PRODUKT')
    @NamedQuery(name = 'PRODUKT.findByID', query = 'select obj from
    PRODUKT where obj.ID = :ID')
    public class Produkt implements Serializable {
    
     @Id
     @Column(name = 'ID')
     private Object id;
    
    
    
    7. If the generated query is used in a servlet as follows:
    
    
     public List?Produkt? getProdukt(int x) {
      EntityManagerFactory emf = Persistence
      .createEntityManagerFactory('TestJPA');
    
      EntityManager em = emf.createEntityManager();
      List?Produkt? results = null;
      try {
       Query query = em.createNamedQuery('PRODUKT.findByID');
       query.setParameter('ID', x);
       results = (List?Produkt?) query.getResultList();
      } finally {
       em.close();
      }
      return results;
     }
    
     /**
      * @see HttpServlet#doGet(HttpServletRequest request, HttpServl
    etResponse response)
      */
     protected void doGet(HttpServletRequest request, HttpServletRes
    ponse response) throws ServletException, IOException {
    
      ProduktManager pm=new ProduktManager();
      Produkt p=pm.getNewProdukt();
      p.setId(2);
      try {
       pm.createProdukt(p);
       List?Produkt? output=getProdukt(2);
       response.getWriter().println(output.size());
    
    
    
      } catch (Exception e) {
       // TODO Auto-generated catch block
       response.getWriter().println(e.getMessage());
      }
     }
    
    The following error will be produced by WebSPhere Application Se
    rver 7.0.0.1:
    
    An error occurred while parsing the query filter 'select obj fro
    m PRODUKT where obj.ID = :ID'. Error message: The name 'PRODUKT'
     is not a recognized entity or identifier. Perhaps you meant Pro
    dukt, which is a close match. Known entity names: [Produkt]
    
    Expected result:
    
    A query generated as:
    
    @Entity
    @Table(name = 'PRODUKT')
    @NamedQuery(name = 'Produkt.findByid', query = 'select obj from
    Produkt where obj.id = :id')
    public class Produkt implements Serializable {
    
     @Id
     @Column(name = 'ID')
     private Object id;
    
    
    Technically, the query name ('Produkt.findByid') and the paramet
    er name ':id' do not matter, it would be better if they were con
    sistent,
    what matters is the entity name and the entity field inside the
    select statement, which must refer to the Java names, not to the
     SQL names.
    

Local fix

Problem summary

  • UML to JPA transformation creates named queries based on SQL
    names rather than Java names.
    

Problem conclusion

  • Fixed in release RSx 752.
    
    Used the Entity/Attribute name instead of the Table/Column
    name
    

Temporary fix

Comments

APAR Information

  • APAR number

    PK81605

  • Reported component name

    SW ARCHITECT WI

  • Reported component ID

    5724I7001

  • Reported release

    751

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2009-03-02

  • Closed date

    2009-04-03

  • Last modified date

    2009-04-03

  • APAR is sysrouted FROM one or more of the following:

  • APAR is sysrouted TO one or more of the following:

Fix information

  • Fixed component name

    SW ARCHITECT WI

  • Fixed component ID

    5724I7001

Applicable component levels

  • R751 PSN

       UP

[{"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Product":{"code":"SSYKBQ","label":"Rational Software Architect Designer for WebSphere Software"},"Component":"","ARM Category":[],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"751","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}},{"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Product":{"code":"SS4JCV","label":"Rational Software Architect for WebSphere Software"},"Component":"","ARM Category":[],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"751","Edition":"","Line of Business":{"code":"LOB15","label":"Integration"}}]

Document Information

Modified date:
03 April 2009