Hibernate 执行mvn wildfly时出错:部署:无法';t确定集合com.sensorhound.aigateway.domain.IOConfiguration.nodeData的主要角色

Hibernate 执行mvn wildfly时出错:部署:无法';t确定集合com.sensorhound.aigateway.domain.IOConfiguration.nodeData的主要角色,hibernate,jpa,one-to-many,hibernate-mapping,hibernate-ogm,Hibernate,Jpa,One To Many,Hibernate Mapping,Hibernate Ogm,嘿,伙计们。我在执行mvnwildfly:deploy时出错。我使用的是wildfly 10.1.0.Final、hibernate ogm 5.0.10.Final和Cassandra 3.0.9。以下是完整的错误信息: [错误]无法执行目标 插件:wildfly maven插件:1.1.0.最终:部署 项目aigateway上的(默认cli):未能执行目标部署: {“WFLYCTL0062:复合操作失败,已回滚。步骤 失败:“=>{”操作步骤-1“=>{”WFLYCTL0080:失败 服务“

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

[错误]无法执行目标 插件:wildfly maven插件:1.1.0.最终:部署 项目aigateway上的(默认cli):未能执行目标部署: {“WFLYCTL0062:复合操作失败,已回滚。步骤 失败:“=>{”操作步骤-1“=>{”WFLYCTL0080:失败 服务“=>{”jboss.persistenceunit.\“aigateway.war#JPAService\”=> “org.jboss.msc.service.StartException在服务中 jboss.persistenceunit.“aigateway.war#JPAService\”: javax.persistence.PersistenceException:[PersistenceUnit:JPAService] 无法生成Hibernate SessionFactory[错误],原因是: javax.persistence.PersistenceException:[PersistenceUnit:JPAService] 无法生成Hibernate SessionFactory[错误],原因是: org.hibernate.HibernateException:无法确定主要角色 加入收藏 com.sensorhound.aigateway.domain.IOConfiguration.nodeData“}”,WFLYCTL0412: 未安装的必需服务:“=> [“jboss.persistenceunit.\“aigateway.war#JPAService\”,“WFLYCTL0180: 缺少/不可用依赖项的服务“=>undefined}” [ERROR]->[Help 1][ERROR][ERROR]以查看的完整堆栈跟踪 如果出现错误,请使用-e开关重新运行Maven。[错误]重新运行Maven 使用-X开关启用完全调试日志记录。[错误][错误]用于 有关错误和可能的解决方案的更多信息,请阅读 以下文章:[错误][帮助1]

以下是“IO_配置”表的代码:

以下是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);  
  }  
}  
我不知道到底发生了什么,当我在谷歌上搜索时,几乎没有关于这个错误的信息。如果您需要信息,我愿意与您分享。谁来帮帮我


谢谢

伙计们,我用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;
  }



}
public class ByteBridge extends NumberBridge implements Serializable {  
  @Override  
  public Object stringToObject(String stringValue) {  
    if (StringHelper.isEmpty(stringValue))  
      return null;  
    return Byte.valueOf(stringValue);  
  }  
}  
@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;
  }



}