执行 mvn wildfly:deploy 时出错:无法确定集合的主要角色 com.sensorhound.aigateway.domain.IOConfiguration.nodeData

Error when doing mvn wildfly:deploy: Couldn't determine main side role for collection com.sensorhound.aigateway.domain.IOConfiguration.nodeData


嘿,伙计们。当我执行 mvn wildfly:deploy 时出现错误。我正在使用 wildfly 10.1.0.Final、hibernate ogm 5.0.10.Final 和 Cassandra 3.0.9。这是完整的错误信息:

[ERROR] Failed to execute goal org.wildfly.plugins:wildfly-maven-plugin:1.1.0.Final:deploy (default-cli) on project aigateway: Failed to execute goal deploy: {"WFLYCTL0062: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-1" => {"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"aigateway.war#JPAService\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"aigateway.war#JPAService\": javax.persistence.PersistenceException: [PersistenceUnit: JPAService] Unable to build Hibernate SessionFactory [ERROR] Caused by: javax.persistence.PersistenceException: [PersistenceUnit: JPAService] Unable to build Hibernate SessionFactory [ERROR] Caused by: org.hibernate.HibernateException: Couldn't determine main side role for collection com.sensorhound.aigateway.domain.IOConfiguration.nodeData"},"WFLYCTL0412: Required services that are not installed:" => ["jboss.persistenceunit.\"aigateway.war#JPAService\""],"WFLYCTL0180: Services with missing/unavailable dependencies" => undefined}}} [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

这是 "IO_CONFIGURATION" table 的代码:

@Entity  
@Indexed  
@Table(name = "IO_CONFIGURATION")  
public class IOConfiguration implements Serializable {  

  private static final long serialVersionUID = 7542743172221933818L;  

  @Id  
  @Column(name = "IO_CONFIGURATION_ID")  
  protected String ioConfigurationId;  

  @Column(name = "ACTIVE")  
  protected Boolean active;  

  @Column(name = "NAME")  
  protected String name;  

  @Column(name = "CONVERSION_TYPE")  
  protected String conversionType;  

  @Column(name = "M_INFO")  
  protected Double mInfo;  

  @Column(name = "B_INFO")  
  protected Double bInfo;  

  @Column(name = "VOLTAGE_DIVIDE")  
  protected String voltageDivide;  

  @Column(name = "SAMPLE_RANGE")  
  protected String sampleRange;  

  @Column(name = "SAMPLE_PERIOD")  
  protected Integer samplePeriod;  

  @Column(name = "STORE_ROW")  
  protected Boolean storeRow;  

  @Column(name = "STORE_CONVERTED")  
  protected Boolean storeConverted;  

  @Column(name = "DEFAULT_GRAPH")  
  protected String defaultGraph;  

  @Column(name = "TITLE")  
  protected String title;  

  @Column(name = "UNIT")  
  protected String unit;  

  @Column(name = "RANGE_LOWERBOUND")  
  protected Integer rangeLowerbound;  

  @Column(name = "RANGE_UPPERBOUND")  
  protected Integer rangeUpperbound;  

  @JsonBackReference  
  @OneToMany(mappedBy = "ioConfiguration")  
  protected List<Alert> alerts;  

  @JsonBackReference  
  @OneToMany(mappedBy = "ioConfiguration")  
  protected List<DataSeriesMeta> dataSeriesMeta;  

  @JsonBackReference  
  @OneToMany(mappedBy = "ioConfiguration")  
  protected List<NodeData> nodeData;  

  @Column(name = "CODE")  
  protected String code;  

  public IOConfiguration() {}  
  //...getters and setter  
}  

这是 "NODE_DATA" table 的代码:

@Entity  
@Indexed  
@IdClass(NodeDataPK.class)  
@Table(name = "NODE_DATA")  
public class NodeData implements Serializable {  

  private static final long serialVersionUID = -3411753713406246973L;  

  @Id  
  @FieldBridge(impl = ByteBridge.class)  
  @JoinColumn(name = "IO_CONFIGURATION_ID", referencedColumnName = "IO_CONFIGURATION_ID")  
  @ManyToOne  
  protected IOConfiguration ioConfiguration;  

  @Id  
  @Column(name = "TIME")  
  protected Long time;  

  @Column(name = "VALUE")  
  protected Double value;  

  public NodeData() {}  

  public NodeDataPK getNodeDataId() {  
    NodeDataPK nodeDataPK = new NodeDataPK();  
    nodeDataPK.setTime(this.time);  
    nodeDataPK.setIoConfigurationId(this.ioConfiguration.getIoConfigurationId());  
    return nodeDataPK;  
  }  

  public void setNodeDataId(NodeDataPK nodeDataPK) {  
    this.time = nodeDataPK.getTime();  
    IOConfigurationDAO ioConfigurationDAO = new IOConfigurationDAO();  
    ioConfigurationDAO.init();  
    IOConfiguration ioConfiguration =  
        ioConfigurationDAO.findIOConfiguration(nodeDataPK.getIoConfigurationId());  
    this.ioConfiguration = ioConfiguration;  
  }  



  /** 
   * @return the ioConfiguration 
   */  
  public IOConfiguration getIoConfiguration() {  
    return ioConfiguration;  
  }  

  /** 
   * @param ioConfiguration the ioConfiguration to set 
   */  
  public void setIoConfiguration(IOConfiguration ioConfiguration) {  
    this.ioConfiguration = ioConfiguration;  
  }  

  /** 
   * @return the time 
   */  
  public Long getTime() {  
    return time;  
  }  

  /** 
   * @param time the time to set 
   */  
  public void setTime(Long time) {  
    this.time = time;  
  }  

  /** 
   * @return the value 
   */  
  public double getValue() {  
    return value;  
  }  

  /** 
   * @param value the value to set 
   */  
  public void setValue(double value) {  
    this.value = value;  
  }  

  /** 
   * @return the serialversionuid 
   */  
  public static long getSerialversionuid() {  
    return serialVersionUID;  
  }  
}  

这是 NodeData 实体的复合主键:

public class NodeDataPK implements Serializable {  

  /** 
   *  
   */  
  private static final long serialVersionUID = -3239860594324151192L;  

  // @Column(name = "IO_CONFIGURATION")  
  protected String ioConfiguration;  

  // @Column(name = "TIME")  
  protected Long time;  

  public NodeDataPK() {}  

  public NodeDataPK(String ioConfigId, Long time) {  
    this.ioConfiguration = ioConfigId;  
    this.time = time;  
  }  

  /** 
   * @return the channelName 
   */  
  public String getIoConfigurationId() {  
    return ioConfiguration;  
  }  

  /** 
   * @param channelName the channelName to set 
   */  
  public void setIoConfigurationId(String ioConfigurationId) {  
    this.ioConfiguration = ioConfigurationId;  
  }  

  /** 
   * @return the time 
   */  
  public Long getTime() {  
    return time;  
  }  

  /** 
   * @param time the time to set 
   */  
  public void setTime(Long time) {  
    this.time = time;  
  }  

  @Override  
  public int hashCode() {  
    return ioConfiguration.hashCode() + time.hashCode();  
  }  

  @Override  
  public boolean equals(Object o) {  
    if (o == null) {  
      return false;  
    }  
    if (!(o instanceof NodeDataPK)) {  
      return false;  
    }  
    NodeDataPK nodeDataPK = (NodeDataPK) o;  
    if (((NodeDataPK) o).getIoConfigurationId() != nodeDataPK.getIoConfigurationId()  
        && ((NodeDataPK) o).getTime() != nodeDataPK.getTime()) {  
      return false;  
    }  

    return true;  
  }  
}  

这是我复制的 ByteBridge:

public class ByteBridge extends NumberBridge implements Serializable {  
  @Override  
  public Object stringToObject(String stringValue) {  
    if (StringHelper.isEmpty(stringValue))  
      return null;  
    return Byte.valueOf(stringValue);  
  }  
}  

我不知道发生了什么,当我 google 时几乎没有关于此错误的消息。如果您需要信息,我愿意分享。请有人帮助我。

谢谢!

伙计们,我使用 EmbeddedId 解决了这个问题。根据 JPA 文档,IdClass 和 EmbeddedId 应该实现相同的目标。但是我找不到我的 IdClass 版本有什么问题。所以我只是切换到 EmbeddedId 并且它有效。这是修改后的代码:

@Embeddable
public class NodeDataPK implements Serializable {

  /**
   * 
   */
  private static final long serialVersionUID = -3239860594324151192L;


  protected String ioConfiguration;

  @Column(name = "TIME")
  protected Long time;

  public NodeDataPK() {}

  public NodeDataPK(String ioConfigId, Long time) {
    this.ioConfiguration = ioConfigId;
    this.time = time;
  }

  /**
   * @return the channelName
   */
  public String getIoConfiguration() {
    return ioConfiguration;
  }

  /**
   * @param channelName the channelName to set
   */
  public void setIoConfiguration(String ioConfigurationId) {
    this.ioConfiguration = ioConfigurationId;
  }

  /**
   * @return the time
   */
  public Long getTime() {
    return time;
  }

  /**
   * @param time the time to set
   */
  public void setTime(Long time) {
    this.time = time;
  }

  @Override
  public int hashCode() {
    return ioConfiguration.hashCode() + time.hashCode();
  }

  @Override
  public boolean equals(Object o) {
    if (o == null) {
      return false;
    }
    if (!(o instanceof NodeDataPK)) {
      return false;
    }
    NodeDataPK nodeDataPK = (NodeDataPK) o;
    if (((NodeDataPK) o).getIoConfiguration() != nodeDataPK.getIoConfiguration()
        && ((NodeDataPK) o).getTime() != nodeDataPK.getTime()) {
      return false;
    }

    return true;
  }
}

@Entity
@Indexed
// @IdClass(NodeDataPK.class)
@Table(name = "NODE_DATA")
public class NodeData implements Serializable {

  private static final long serialVersionUID = -3411753713406246973L;

  // @Id
  // @FieldBridge(impl = ByteBridge.class)
  // @JoinColumn(name = "IO_CONFIGURATION_ID", referencedColumnName = "IO_CONFIGURATION_ID")
  // @ManyToOne
  // @JsonManagedReference
  // protected IOConfiguration ioConfiguration;
  //
  // @Id
  // @Column(name = "TIME")
  // protected Long time;

  @DocumentId
  @EmbeddedId
  @FieldBridge(impl = ByteBridge.class)
  protected NodeDataPK nodeDataPK;

  @JoinColumn(name = "IO_CONFIGURATION")
  @MapsId("ioConfiguration")
  @ManyToOne
  protected IOConfiguration ioConfiguration;

  @Column(name = "VALUE")
  protected Double value;

  public NodeData() {}

  // public NodeDataPK getNodeDataId() {
  // NodeDataPK nodeDataPK = new NodeDataPK();
  // nodeDataPK.setTime(this.time);
  // nodeDataPK.setIoConfiguration(this.ioConfiguration.getIoConfigurationId());
  // return nodeDataPK;
  // }
  //
  // public void setNodeDataId(NodeDataPK nodeDataPK) {
  // this.time = nodeDataPK.getTime();
  // IOConfigurationDAO ioConfigurationDAO = new IOConfigurationDAO();
  // ioConfigurationDAO.init();
  // IOConfiguration ioConfiguration =
  // ioConfigurationDAO.findIOConfiguration(nodeDataPK.getIoConfiguration());
  // this.ioConfiguration = ioConfiguration;
  // }

  public NodeDataPK getNodeDataId() {
    return this.nodeDataPK;
  }

  public void setNodeDataId(NodeDataPK nodeDataPK) {
    this.nodeDataPK = nodeDataPK;
  }



  /**
   * @return the ioConfiguration
   */
  public IOConfiguration getIoConfiguration() {
    return ioConfiguration;
  }

  /**
   * @param ioConfiguration the ioConfiguration to set
   */
  public void setIoConfiguration(IOConfiguration ioConfiguration) {
    this.ioConfiguration = ioConfiguration;
  }

  // /**
  // * @return the time
  // */
  // public Long getTime() {
  // return time;
  // }
  //
  // /**
  // * @param time the time to set
  // */
  // public void setTime(Long time) {
  // this.time = time;
  // }

  public Long getTime() {
    return this.getNodeDataId().getTime();
  }

  public void setTime(Long time) {
    this.getNodeDataId().setTime(time);
  }

  /**
   * @return the value
   */
  public double getValue() {
    return value;
  }

  /**
   * @param value the value to set
   */
  public void setValue(double value) {
    this.value = value;
  }

  /**
   * @return the serialversionuid
   */
  public static long getSerialversionuid() {
    return serialVersionUID;
  }



}