为什么我收到如下警告信息:恢复OneToOne或ManyToOne属性的延迟设置?

时间:2014-09-10 05:11:26

标签: java jpa

大家好,

祝你有个愉快的一天。在我的maven项目中,我使用JPA进行后端通信和eclipse-link。但是当我尝试在我的Model组件上执行延迟加载时,我收到了上述警告信息。我已经将插件添加到pom.xml,并且还在persistent.xml中,添加了,仍然无法解决我的问题。请有人帮帮我。下面是我的实体类。

Gdu.java

package com.model;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;


@Entity
@Table(name = "GDU")
@NamedQueries({
@NamedQuery(name = "Gdu.findAll", query = "SELECT g FROM Gdu g"),
@NamedQuery(name = "Gdu.findByGduId", query = "SELECT g FROM Gdu g WHERE g.gduId = :gduId"),
@NamedQuery(name = "Gdu.findByName", query = "SELECT g FROM Gdu g WHERE g.name = :name"),
@NamedQuery(name = "Gdu.findByHttpPort", query = "SELECT g FROM Gdu g WHERE g.httpPort = :httpPort"),
@NamedQuery(name = "Gdu.findByModbusPort", query = "SELECT g FROM Gdu g WHERE g.modbusPort = :modbusPort")})
@SequenceGenerator(name="SEQ5", sequenceName="gduSeq", allocationSize=1)
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@gduId")




 public class Gdu implements Serializable {
        private static final long serialVersionUID = 1L;
        // @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
        @Id
        @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ5")
        @Basic(optional = false)
        @NotNull
        @Column(name = "GDU_ID")
        private BigDecimal gduId;
        @Size(max = 10)
        @Column(name = "NAME")
        private String name;
        @Basic(optional = false)
        @NotNull
        @Column(name = "HTTP_PORT")
        private BigInteger httpPort;
        @Basic(optional = false)
        @NotNull
        @Column(name = "MODBUS_PORT")
        private BigInteger modbusPort;
        @JoinColumn(name = "PLANT_ID", referencedColumnName = "PLANT_ID")
        @ManyToOne(optional = false, fetch = FetchType.LAZY)
        private Plant plantId;
        @OneToMany(mappedBy = "gduId", fetch = FetchType.LAZY)
        private Collection<Inverter> inverterCollection;
        @JoinColumn(name = "GDUTYPE_ID", referencedColumnName = "GDUTYPE_ID")
        @ManyToOne(optional = false,fetch = FetchType.LAZY)
        private Gdutype gdutypeId;

        public Gdu() {
        }

        public Gdu(BigDecimal gduId) {
        this.gduId = gduId;
        }

        public Gdu(BigDecimal gduId, BigInteger httpPort, BigInteger modbusPort) {
        this.gduId = gduId;
        this.httpPort = httpPort;
        this.modbusPort = modbusPort;
        }

        //override equals and hashcode and setters and getters are here
        } 

这里对于plantId和gdutypeId我收到了警告。

The warning is :  [EL Info]: 2014-09-05 14:39:14.144--ServerSession(1385008216)--EclipseLink, version: Eclipse Persistence Services - 2.4.0.v20120608-r11652
[EL Warning]: metadata: 2014-09-05 14:39:14.264--ServerSession(1385008216)--Reverting the lazy setting on the OneToOne or ManyToOne attribute [gdutypeId] for the entity class [class com.model.Gdu] since weaving was not enabled or did not occur.
[EL Warning]: metadata: 2014-09-05 14:39:14.264--ServerSession(1385008216)--Reverting the lazy setting on the OneToOne or ManyToOne attribute [plantId] for the entity class [class com.model.Gdu] since weaving was not enabled or did not occur.

请帮帮我。提前谢谢。

Here is Inverter and Plant and GduType. Please have a look

package com.model;
//imports are here
@Entity
@Table(name = "GDUTYPE")
@NamedQueries({
    @NamedQuery(name = "Gdutype.findAll", query = "SELECT g FROM Gdutype g"),
    @NamedQuery(name = "Gdutype.findByGdutypeId", query = "SELECT g FROM Gdutype g WHERE g.gdutypeId = :gdutypeId"),
    @NamedQuery(name = "Gdutype.findByProductName", query = "SELECT g FROM Gdutype g WHERE g.productName = :productName"),
    @NamedQuery(name = "Gdutype.findByApiName", query = "SELECT g FROM Gdutype g WHERE g.apiName = :apiName"),
    @NamedQuery(name = "Gdutype.findByApiVersion", query = "SELECT g FROM Gdutype g WHERE g.apiVersion = :apiVersion")})
public class Gdutype implements Serializable {
    private static final long serialVersionUID = 1L;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "GDUTYPE_ID")
    private BigDecimal gdutypeId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "PRODUCT_NAME")
    private String productName;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "API_NAME")
    private String apiName;
    @Size(max = 5)
    @Column(name = "API_VERSION")
    private String apiVersion;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "gdutypeId",fetch = FetchType.LAZY)
    private Collection<Gdu> gduCollection;

    public Gdutype() {
    }

    public Gdutype(BigDecimal gdutypeId) {
        this.gdutypeId = gdutypeId;
    }
    public Gdutype(BigDecimal gdutypeId, String productName, String apiName) {
        this.gdutypeId = gdutypeId;
        this.productName = productName;
        this.apiName = apiName;
    }
    //setters and getters ,hashcode,equals
}


package com.model;
@Entity
@Table(name = "INVERTER")
@NamedQueries({
    @NamedQuery(name = "Inverter.findAll", query = "SELECT i FROM Inverter i"),
    @NamedQuery(name = "Inverter.findByInverterId", query = "SELECT i FROM Inverter i WHERE i.inverterId = :inverterId"),
    @NamedQuery(name = "Inverter.findByName", query = "SELECT i FROM Inverter i WHERE i.name = :name"),
    @NamedQuery(name = "Plant.findByNominalPower", query = "SELECT p FROM Plant p WHERE p.nominalPower = :nominalPower")})
@SequenceGenerator(name="SEQ4", sequenceName="inverterSeq", allocationSize=1)
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@inverterId")
public class Inverter implements Serializable {
    private static final long serialVersionUID = 1L;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ4")    
    @Basic(optional = false)
    @NotNull
    @Column(name = "INVERTER_ID")
    private BigDecimal inverterId;
    @Size(max = 45)
    @Column(name = "NAME")
    private String name;
    @Basic(optional = false)
    @NotNull
    @Column(name = "NOMINAL_POWER")
    private double nominalPower;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "inverterId", fetch = FetchType.LAZY)
    private Collection<Mppt> mpptCollection;
    @JoinColumn(name = "PLANT_ID", referencedColumnName = "PLANT_ID")
    @ManyToOne(optional = false, , fetch = FetchType.LAZY)
    private Plant plantId;
    @JoinColumn(name = "PCI_ID", referencedColumnName = "PCI_ID")
    @ManyToOne(" fetch = FetchType.LAZY)
    private Pci pciId;
    @JoinColumn(name = "INVERTERTYPE_ID", referencedColumnName = "IT_ID")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Invertertype invertertypeId;
    @JoinColumn(name = "GDU_ID", referencedColumnName = "GDU_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private Gdu gduId;
    public Inverter() {  }
}


package com.model;
@Entity
@Table(name = "PLANT")
@NamedQueries({
    @NamedQuery(name = "Plant.findAll", query = "SELECT p FROM Plant p"),
    @NamedQuery(name = "Plant.findByPlantId", query = "SELECT p FROM Plant p WHERE p.plantId = :plantId"),
    @NamedQuery(name = "Plant.findByName", query = "SELECT p FROM Plant p WHERE p.name = :name"),
    @NamedQuery(name = "Plant.findByOperator", query = "SELECT p FROM Plant p WHERE p.operator = :operator"),
    @NamedQuery(name = "Plant.findByCommissioning", query = "SELECT p FROM Plant p WHERE p.commissioning = :commissioning"),
    @NamedQuery(name = "Plant.findByNominalPower", query = "SELECT p FROM Plant p WHERE p.nominalPower = :nominalPower"),
    @NamedQuery(name = "Plant.findByContador", query = "SELECT p FROM Plant p WHERE p.contador = :contador")})
@SequenceGenerator(name="SEQ2", sequenceName="plantSeq", allocationSize=1)
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@plantId")
public class Plant implements Serializable {
    private static final long serialVersionUID = 1L;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ2")
    @Basic(optional = false)
    @NotNull
    @Column(name = "PLANT_ID")
    private BigDecimal plantId;
    @Size(max = 45)
    @Column(name = "NAME")
    private String name;
    @Size(max = 30)
    @Column(name = "OPERATOR")
    private String operator;
    @Column(name = "COMMISSIONING")
    @Temporal(TemporalType.TIMESTAMP)
    private Date commissioning;
    @Basic(optional = false)
    @NotNull
    @Column(name = "NOMINAL_POWER")
    private double nominalPower;
    @Column(name = "CONTADOR")
    private BigInteger contador;
    @Column(name = "LONGITUDE")
    private BigDecimal longitude;
    @Column(name = "LATITUDE")
    private BigDecimal latitude;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "plantId", fetch = FetchType.LAZY)
    private Collection<Sensor> sensorCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "plant", fetch = FetchType.LAZY)
    private Collection<Userplant> userplantCollection;
    @JoinColumn(name = "REPORT_ID", referencedColumnName = "REPORT_ID")
    @ManyToOne( fetch = FetchType.LAZY)
    private Report reportId;
    @JoinColumn(name = "INSTALLATION_ID", referencedColumnName = "INSTALLATION_ID")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Installation installationId;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "plantId", fetch = FetchType.LAZY)
    private Collection<Gdu> gduCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "plantId", fetch = FetchType.LAZY)
    private Collection<Inverter> inverterCollection;

    public Plant() {
    }

    public Plant(BigDecimal plantId) {
        this.plantId = plantId;
    }

    public Plant(BigDecimal plantId, double nominalPower) {
        this.plantId = plantId;
        this.nominalPower = nominalPower;
    }
}

1 个答案:

答案 0 :(得分:1)

您正在使用PlantGduType上的延迟加载的OneToMany和ManyToOne映射。这需要对POJO(Weaving)进行字节码更改。

EclipseLink使用编织来增强JPA实体和Plain Old Java Object(POJO)类,例如延迟加载,更改跟踪,获取组和内部优化。

EclipseLink使用编织为POJO类启用以下内容:

  1. 延迟加载(间接)
  2. 更改跟踪
  3. 获取群组
  4. 内部优化。
  5. 要解决此警告,您有两个选项:

    1. 删除延迟加载。
    2. 配置Dynamic weaving
    3. 参考:EclipseLink