This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 78634

Summary: Renaming @Entity class fails to rename bodies of @NamedQueries
Product: javaee Reporter: Jesse Glick <jglick>
Component: RefactoringAssignee: Erno Mononen <emononen>
Status: VERIFIED DUPLICATE    
Severity: blocker    
Priority: P3    
Version: 5.x   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:

Description Jesse Glick 2006-06-20 19:13:41 UTC
060619 release55 build. If you have an entity class like

@Entity
@Table(name = "whatever")
@NamedQueries({
  @NamedQuery(name = "X.findByK", query = "SELECT x FROM X x WHERE x.k = :k")
})
public class X implements Serializable { 
  ...
}

and a matching entry in persistence.xml

  <class>somepkg.X</class>

and then you rename the class X to X2, the class is correctly renamed, as is the
entry in persistence.xml, but the @NamedQuery is untouched. This produces a
runtime error:

Exception in thread "main" Local Exception Stack: 
Exception [TOPLINK-8006] (Oracle TopLink Essentials - 2006.4 (Build 060412)):
oracle.toplink.essentials.exceptions.EJBQLException
Exception Description: A problem was encountered resolving the class name - The
descriptor for [X2] was not found.
        at
oracle.toplink.essentials.exceptions.EJBQLException.missingDescriptorException(EJBQLException.java:155)
        at
oracle.toplink.essentials.internal.parsing.ParseTreeContext.classForSchemaName(ParseTreeContext.java:135)
        at
oracle.toplink.essentials.internal.parsing.SelectNode.getClassOfFirstVariable(SelectNode.java:342)
        at
oracle.toplink.essentials.internal.parsing.SelectNode.getReferenceClass(SelectNode.java:330)
        at
oracle.toplink.essentials.internal.parsing.ParseTree.getReferenceClass(ParseTree.java:402)
        at
oracle.toplink.essentials.internal.parsing.ParseTree.adjustReferenceClassForQuery(ParseTree.java:79)
        at
oracle.toplink.essentials.internal.parsing.EJBQLParseTree.populateReadQueryInternal(EJBQLParseTree.java:135)
        at
oracle.toplink.essentials.internal.parsing.EJBQLParseTree.populateQuery(EJBQLParseTree.java:95)
        at
oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:214)
        at
oracle.toplink.essentials.queryframework.EJBQLPlaceHolderQuery.processEjbQLQuery(EJBQLPlaceHolderQuery.java:96)
[...]

To fix the error you need to also rename the query body:

  @NamedQuery(name = "X.findByK", query = "SELECT x FROM X2 x WHERE x.k = :k")
                                                         ^^

Renaming the query name (e.g. to "X2.findByK") is not safe unless you can locate
all code calling EntityManager.createNamedQuery("X.findByK") and also update
those calls.
Comment 1 Rochelle Raccah 2006-06-20 21:08:21 UTC

*** This issue has been marked as a duplicate of 73934 ***
Comment 2 Jesse Glick 2006-06-20 22:53:14 UTC
Yes, same issue.