History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: IDEA-18328
Type: Bug Bug
Status: Open Open
Assignee: Gregory Shrago
Reporter: Christian Nelson
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
IDEA: Feedback

Abstract class is flagged with inappropriate "constructor should have no-arg constructor" inspection error

Created: 05 Jun 08 02:10   Updated: 05 Jun 08 10:13
Component/s: J2EE.Hibernate

File Attachments: None
Image Attachments:

1. hibernate-constructor-on-abstract-class-1.jpg
(106 kb)

2. hibernate-constructor-on-abstract-class-2.jpg
(42 kb)
Environment: Windows

Build: 7,860
Severity: Low


 Description  « Hide
Abstract classes that are hibernate mapped are flagged with an inappropriate "constructor should have no-arg constructor" error. Non-abstract subclasses must have such a constructor, but abstract base classes don't have the same requirement.

We have a concrete class EmailNotification which extends an abstract base class Notification. EmailNotification has a no-arg constructor, but Notification does not. Notification cannot be instantiated directly nor by hibernate, thus is doesn't need such a constructor. The inspection should only apply to non-abstract classes. Here's some simplified code:

public abstract class Notification {

    protected Long id;
    protected Subscription subscription;

    protected Notification(Subscription subscription) {
        this.subscription = subscription;
    }
    
    // ...
}

public class EmailNotification extends Notification {

    private Email email;

    EmailNotification() {
        super(null);
    }

    public Email getEmail() {
        return email;
    }

    // ...
}

The first screen shot (hibernate-constructor-on-abstract-class-1.jpg) shows the class and error message. The second screenshot (hibernate-constructor-on-abstract-class-2.jpg) shows part of the hibernate mapping xml (also indicating the class is abstract).



 All   Comments   Work Log   Change History      Sort Order:
There are no comments yet on this issue.