2

I've made some changes on my application. I am quite sure that it has become slow when loading data from database due to changes on the entities (and this after going through some profilings on Netbeans IDE).

What I have added is some methods and transient variables. Here is one Entity of my JPA entities. The exact question is is there something wrong with it?

/**
 *
 * @author Houssem
 */
@Entity
@Table(name = "t_feeder")
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Feeder.findAll", query = "SELECT f FROM Feeder f"),
    @NamedQuery(name = "Feeder.findById", query = "SELECT f FROM Feeder f WHERE f.id = :id"),
    @NamedQuery(name = "Feeder.findByIsVip", query = "SELECT f FROM Feeder f WHERE f.isVip = :isVip"),
    @NamedQuery(name = "Feeder.findByFeederNumber", query = "SELECT f FROM Feeder f WHERE f.feederNumber = :feederNumber"),
    @NamedQuery(name = "Feeder.findByPeriority", query = "SELECT f FROM Feeder f WHERE f.periority = :periority"),
    @NamedQuery(name = "Feeder.findBySceneX", query = "SELECT f FROM Feeder f WHERE f.sceneX = :sceneX"),
    @NamedQuery(name = "Feeder.findByPrimaryStation", query = "SELECT f FROM Feeder f WHERE f.primaryStationId = :ps"),
    @NamedQuery(name = "Feeder.findByPsAndNumber", query = "SELECT f FROM Feeder f WHERE f.primaryStationId = :ps AND f.feederNumber = :number"),
    @NamedQuery(name = "Feeder.findBySceneY", query = "SELECT f FROM Feeder f WHERE f.sceneY = :sceneY")})
public class Feeder implements Serializable {

    private static final long serialVersionUID = 1L;
    public static final String FIND_BY_NUMBER = "Feeder.findByFeederNumber";
    public static final String FIND_BY_PS = "Feeder.findByPrimaryStation";
    public static final String FIND_BY_PS_AND_NUMBER = "Feeder.findByPsAndNumber";

    transient private PropertyChangeSupport propertySupport;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @Column(name = "is_vip")
    private boolean isVip;
    @Lob
    @Column(name = "note", length = 65535)
    private String note;
    @Basic(optional = false)
    @Column(name = "feederNumber")
    private String feederNumber;
    @Column(name = "periority")
    private Integer periority;
    @Column(name = "scene_x")
    private Integer sceneX;
    @Column(name = "scene_y")
    private Integer sceneY;
    @OneToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}, fetch = FetchType.LAZY, mappedBy = "feederId")
    private Collection<SecondaryStation> secondaryStationCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "feederId")
    private Collection<Port> portCollection;
    @OneToMany(cascade = CascadeType.REMOVE, mappedBy = "feederId", fetch = FetchType.LAZY)
    private Collection<StationContinuity> sourceStationContinuityCollection;
    @OneToMany(cascade = CascadeType.REMOVE, mappedBy = "linkToFeederId", fetch = FetchType.LAZY)
    private Collection<StationContinuity> targetStationContinuityCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "feederId", fetch = FetchType.LAZY)
    private Collection<AlarmedFeeder> alarmedFeederCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "feederId", fetch = FetchType.LAZY)
    private Collection<Comment> commentCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "feederId", fetch = FetchType.LAZY)
    private Collection<FeederLoading> feederLoadingCollection;
    @OneToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}, mappedBy = "feederId", fetch = FetchType.LAZY)
    private Collection<ConnectorNode> connectorNodeCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "feederId")
    private Collection<Signalization> signalizationCollection;
    @JoinColumn(name = "primaryStationId", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private PrimaryStation primaryStationId;
    @OneToMany(mappedBy = "feederId")
    private Collection<Link> linkCollection;
    @Column(name = "date_synchronization")
    @Temporal(TemporalType.TIMESTAMP)
    private Date synchronizationDate;
    @Column(name = "date_modification")
    @Temporal(TemporalType.TIMESTAMP)
    private Date modificationDate;
    @Column(name = "synchronized")
    private boolean isSynchronized;

    //_______________ Export List Ref objects ________________
    transient private Collection<SecondaryStation> secondaryStationsRef;
    transient private Collection<StationContinuity> sourceStationContinuitysRef;
    transient private Collection<StationContinuity> targetStationContinuitysRef;
    transient private Collection<Comment> commentsRef;
    transient private Collection<ConnectorNode> connectorNodesRef;
    transient private Collection<Signalization> signalizationsRef;
    transient private Collection<EquipmentFileItem> equipmentFileItemsRef;
    //Les port c'est automatique, puis avec get tjrs

    //Getters & Setters - used only to add references, these objects are not added to DB
    public Collection<EquipmentFileItem> getEquipmentFileItemsRef() {
        return equipmentFileItemsRef;
    }

    public void setEquipmentFileItemsRef(Collection<EquipmentFileItem> equipmentFileItemsRef) {
        this.equipmentFileItemsRef = equipmentFileItemsRef;
    }

    public Collection<SecondaryStation> getSecondaryStationsRef() {
        return secondaryStationsRef;
    }

    public void setSecondaryStationsRef(Collection<SecondaryStation> secondaryStationCollection) {
        this.secondaryStationsRef = secondaryStationCollection;
    }

    public Collection<StationContinuity> getSourceStationContinuitiesRef() {
        return sourceStationContinuitysRef;
    }

    public void setSourceStationContinuitiesRef(Collection<StationContinuity> sourceStationContinuitysRef) {
        this.sourceStationContinuitysRef = sourceStationContinuitysRef;
    }

    public Collection<StationContinuity> getTargetStationContinuitiesRef() {
        return targetStationContinuitysRef;
    }

    public void setTargetStationContinuitiesRef(Collection<StationContinuity> targetStationContinuitysRef) {
        this.targetStationContinuitysRef = targetStationContinuitysRef;
    }

    public Collection<Comment> getCommentsRef() {
        return commentsRef;
    }

    public void setCommentsRef(Collection<Comment> commentsRef) {
        this.commentsRef = commentsRef;
    }

    public Collection<ConnectorNode> getConnectorNodesRef() {
        return connectorNodesRef;
    }

    public void setConnectorNodesRef(Collection<ConnectorNode> connectorNodesRef) {
        this.connectorNodesRef = connectorNodesRef;
    }

    public Collection<Signalization> getSignalizationsRef() {
        return signalizationsRef;
    }

    public void setSignalizationsRef(Collection<Signalization> signalizationsRef) {
        this.signalizationsRef = signalizationsRef;
    }

    //_______________ End Export Stuff________________
    public Feeder() {
        propertySupport = new PropertyChangeSupport(this);
    }

    public Feeder(Long id) {
        this.id = id;
    }

    public Feeder(Long id, String feederNumber) {
        this.id = id;
        this.feederNumber = feederNumber;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public boolean getIsVip() {
        return isVip;
    }

    public void setIsVip(boolean isVip) {
        this.isVip = isVip;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public String getFeederNumber() {
        return feederNumber;
    }

    public void setFeederNumber(String feederNumber) {
        this.feederNumber = feederNumber;
    }

    public Integer getPeriority() {
        return periority;
    }

    public void setPeriority(Integer periority) {
        this.periority = periority;
    }

    public Integer getSceneX() {
        return sceneX;
    }

    public void setSceneX(Integer sceneX) {
        this.sceneX = sceneX;
    }

    public Integer getSceneY() {
        return sceneY;
    }

    public void setSceneY(Integer sceneY) {
        this.sceneY = sceneY;
    }

    public Collection<SecondaryStation> fetchSecondaryStationCollection() {
        return secondaryStationCollection;
    }

    public void setSecondaryStationCollection(Collection<SecondaryStation> secondaryStationCollection) {
        this.secondaryStationCollection = secondaryStationCollection;
    }

    public Collection<Port> fetchPortCollection() {
        return portCollection;
    }

    public Collection<Port> getPortCollection() {
        return portCollection;
    }

    public void setPortCollection(Collection<Port> portCollection) {
        this.portCollection = portCollection;
    }

    public Collection<StationContinuity> fetchSourceStationContinuityCollection() {
        return sourceStationContinuityCollection;
    }

    public void setSourceStationContinuityCollection(Collection<StationContinuity> stationContinuityCollection) {
        this.sourceStationContinuityCollection = stationContinuityCollection;
    }

    public Collection<StationContinuity> fetchTargetStationContinuityCollection() {
        return targetStationContinuityCollection;
    }

    public void setTargetStationContinuityCollection(Collection<StationContinuity> stationContinuityCollection1) {
        this.targetStationContinuityCollection = stationContinuityCollection1;
    }

    public Collection<AlarmedFeeder> fetchAlarmedFeederCollection() {
        return alarmedFeederCollection;
    }

    public void setAlarmedFeederCollection(Collection<AlarmedFeeder> alarmedFeederCollection) {
        this.alarmedFeederCollection = alarmedFeederCollection;
    }

    public Collection<Comment> fetchCommentCollection() {
        return commentCollection;
    }

    public void setCommentCollection(Collection<Comment> commentCollection) {
        this.commentCollection = commentCollection;
    }

    public Collection<FeederLoading> fetchFeederLoadingCollection() {
        return feederLoadingCollection;
    }

    public void setFeederLoadingCollection(Collection<FeederLoading> feederLoadingCollection) {
        this.feederLoadingCollection = feederLoadingCollection;
    }

    public Collection<ConnectorNode> fetchConnectorNodeCollection() {
        return connectorNodeCollection;
    }

    public void setConnectorNodeCollection(Collection<ConnectorNode> connectorNodeCollection) {
        this.connectorNodeCollection = connectorNodeCollection;
    }

    public Collection<Signalization> fetchSignalizationCollection() {
        return signalizationCollection;
    }

    public void setSignalizationCollection(Collection<Signalization> signalizationCollection) {
        this.signalizationCollection = signalizationCollection;
    }

    public long getPrimaryStationId() {
        if (primaryStationId != null) {
            return primaryStationId.getId();
        }
        return 0;
    }

    public PrimaryStation fetchPrimaryStation() {
        return primaryStationId;
    }

    public void setPrimaryStationId(PrimaryStation primaryStationId) {
        this.primaryStationId = primaryStationId;
    }

    public Collection<Link> fetchLinkCollection() {
        return linkCollection;
    }

    public void setLinkCollection(Collection<Link> linkCollection) {
        this.linkCollection = linkCollection;
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.removePropertyChangeListener(listener);
    }

    public Date getSynchronizationDate() {
        return synchronizationDate;
    }

    public void setSynchronizationDate(Date synchronizationDate) {
        this.synchronizationDate = synchronizationDate;
    }

    public Date getModificationDate() {
        return modificationDate;
    }

    public void setModificationDate(Date modificationDate) {
        this.modificationDate = modificationDate;
    }

    public boolean isIsSynchronized() {
        return isSynchronized;
    }

    public void setIsSynchronized(boolean isSynchronized) {
        this.isSynchronized = isSynchronized;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Feeder)) {
            return false;
        }
        Feeder other = (Feeder) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Feeder[ number=" + this.feederNumber + " ]";
    }

}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Houssam Badri
  • 2,441
  • 3
  • 29
  • 60
  • 2
    Turn on SQL logging and see what queries are being generated. Without that you are only guessing. https://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging – Alan Hay Aug 18 '16 at 07:50
  • 1
    In addition, a profiler would help tell you where the 'extra' time is being taken. Nothing overly obvious is wrong with the entity - the devil is in the details of how you are using it. As OneToMany relationships are lazy by default, what are you doing to access them that you notice they are slow, how are you obtaining the initial 'feeder' instance, and how many records are in the database? – Chris Aug 22 '16 at 16:11

1 Answers1

1

The entity Feeder has a lot!!!! of one-to-many relationships because of that all you queries will be slow(eclipselink has no issue with that).It would be more efficient if you transform all the one-to-many to unidirectional many-to-one (also the entity will look more clear and comprehensible ).

SEY_91
  • 1,615
  • 15
  • 26