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 73934 - [55cat] Incomplete refactoring of Java Persistence entity fields/properties
Summary: [55cat] Incomplete refactoring of Java Persistence entity fields/properties
Status: NEW
Alias: None
Product: javaee
Classification: Unclassified
Component: Persistence (show other bugs)
Version: 5.x
Hardware: All All
: P2 blocker with 1 vote (vote)
Assignee: Andrei Badea
URL:
Keywords:
: 73925 74540 78606 78634 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-03-23 18:05 UTC by ievans
Modified: 2012-05-12 07:51 UTC (History)
2 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ievans 2006-03-23 18:05:47 UTC
When you rename Java Persistence entity names or entity fields/properties in
NetBeans 5.5, the refactoring engine doesn't rename annotation metadata
elements, resulting in deployment and runtime errors.

For example, if I have a BankCustomer entity class with a persistent field
customerId:
@Entity
@Table(name = "BANK_CUSTOMER")
@NamedQueries( {
    @NamedQuery(
            name = "BankCustomer.FindByCustomerId", 
            query = "SELECT a FROM BankCustomer a WHERE a.customerId =
:customerId"), 
...
)}
public class BankCustomer {
...
    @Id
    @GeneratedValue(strategy=GenerationType.TABLE, generator="customerIdGen")
    @Column(name = "CUSTOMER_ID", nullable = false)
    private String custoemrId;
...
}

And I want to rename the entity class to Customer, and customerId to id, the
refactoring engine doesn't refactor the metadata:
@Entity
@Table(name = "BANK_CUSTOMER")
@NamedQueries( {
    @NamedQuery(
            name = "BankCustomer.FindByCustomerId", 
            query = "SELECT a FROM BankCustomer a WHERE a.customerId =
:customerId"), 
...
)}
public class Customer {
...
    @Id
    @GeneratedValue(strategy=GenerationType.TABLE, generator="customerIdGen")
    @Column(name = "CUSTOMER_ID", nullable = false)
    private String id;
...
}

There are three errors here:
1. The NamedQuery name doesn't match the entity class name and the renamed field.
2. The query is incorrect as it's schemaname is still BankCustomer, but should
have been renamed to Customer.
3. The fields and named parameters in the query are also incorrect ("customerId"
rather than "id").

The mappedBy element in relationship annotations are also not updated during
refactoring, which results in deployment errors.

The refactoring engine should update annotation metadata.
Comment 1 Jiri Kovalsky 2006-03-23 18:23:06 UTC
In my opinion this can be seen rather as a bug in J2EE refactoring. Besides,
reassigning to appropriate component.
Comment 2 Jiri Kovalsky 2006-03-23 18:24:56 UTC
Changing subcomponent as well.
Comment 3 Petr Blaha 2006-03-24 08:51:37 UTC
*** Issue 73925 has been marked as a duplicate of this issue. ***
Comment 4 Petr Blaha 2006-03-24 08:53:37 UTC
I'm changing priority to P2 since this feature is very important for persitence
stuff.
Comment 5 Erno Mononen 2006-04-14 07:58:18 UTC
Partially fixed, mappedBy references should be now updated. 
Comment 6 Erno Mononen 2006-05-05 12:02:29 UTC
*** Issue 74540 has been marked as a duplicate of this issue. ***
Comment 7 Erno Mononen 2006-05-31 09:59:55 UTC
Changing this to enhancement as agreed with Petr Blaha. Issue with mappedBy 
references is now resolved, and support for ejb-ql refactoring is something that 
has not been present in previous releases.
Comment 8 Erno Mononen 2006-06-20 17:17:25 UTC
*** Issue 78606 has been marked as a duplicate of this issue. ***
Comment 9 Rochelle Raccah 2006-06-20 17:26:45 UTC
Closed duplicate issue was from netcat - adding prefix here.
Comment 10 Rochelle Raccah 2006-06-20 21:08:20 UTC
*** Issue 78634 has been marked as a duplicate of this issue. ***
Comment 11 Rochelle Raccah 2006-06-20 21:10:11 UTC
2 duplicates filed in the past day - perhaps this should be a defect, not an
enhancement?

Also, be sure to see Jesse's comments on Issue 78634.
Comment 12 Petr Jiricka 2006-06-21 08:39:15 UTC
Since the original problem reported here is partially fixed, would it be useful
to file a new issue with just the remaining part?

Regarding a possible solution, would it be possible to display a warning to the
user prompting her to manually update the NamedQueries?
Comment 13 Sergey Petrov 2012-02-09 19:15:25 UTC
nq refactoring isn't supported yet, but nqs are verified now and warning is shown if necessary, may work in this case (from 7.2)
Comment 14 Sergey Petrov 2012-05-12 07:51:30 UTC
mappedBy is implemented in 205539
as named queries parsing/completion etc is added in 7.2 it may be possible to add named queries refactoring later also.