Java Hibernate-子类必须在它之后绑定';母亲班

Java Hibernate-子类必须在它之后绑定';母亲班,java,hibernate,hibernate-5.x,hibernate-4.x,Java,Hibernate,Hibernate 5.x,Hibernate 4.x,将hibernate从版本4.3.7.Final升级到版本5.3.18.Final后,我得到以下错误 @Entity @Audited @AuditPermission(Permission.VIEW_INDIVIDUAL) public class Individual implements ITemporalEntity { @Id @Column(name = "Individual_id") @GeneratedValue(strategy

将hibernate从版本4.3.7.Final升级到版本5.3.18.Final后,我得到以下错误

@Entity
@Audited
@AuditPermission(Permission.VIEW_INDIVIDUAL)
public class Individual implements ITemporalEntity {

    @Id
    @Column(name = "Individual_id")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "Individual_generator")
    @SequenceGenerator(name = "Individual_generator", initialValue = 1, allocationSize = 1, sequenceName = "Individual_id_seq")
    private Long id;
    @Embedded
    private TemporalEntity temporal = new TemporalEntity();
    @Override
    public DateTime getCreateDate() {
     return temporal.getCreateDate();
    }

    @Override
    public void setCreateDate(DateTime createDate) {
     temporal.setCreateDate(createDate);

    }
    .......
    ...

   }
临时性

@Embeddable
public class TemporalEntity {

@Column(updatable = false)
private DateTime createDate;

@Column
private DateTime lastModifiedDate;

@ManyToOne
@JoinColumn(name = "created_by_id", updatable = false)
private AdminUser createdBy;

@ManyToOne
@JoinColumn(name = "last_modified_by_id")
private AdminUser lastModifiedBy;

@Column(nullable = false, columnDefinition = "boolean not null default false")
private boolean deleted = false;

public DateTime getCreateDate() {
    return createDate;
}

public void setCreateDate(DateTime createDate) {
    if (createDate == null) {
        //ignore attempts to clear this field
        return;
        //throw new IllegalStateException("Null create date not allowed");
    }
    this.createDate = createDate;
}

public DateTime getLastModifiedDate() {
    return lastModifiedDate;
}

public void setLastModifiedDate(DateTime lastModifiedDate) {
    if (lastModifiedDate == null) {
        //ignore attempts to clear this field
        return;
        //throw new IllegalStateException("Null last modified date not allowed");
    }
    this.lastModifiedDate = lastModifiedDate;
}

public AdminUser getCreatedBy() {
    return createdBy;
}

public void setCreatedBy(AdminUser createdBy) {
    if (createdBy == null) {
        //ignore attempts to clear this field
        return;
        //throw new IllegalStateException("Null created by not allowed");
    }
    this.createdBy = createdBy;
}

public AdminUser getLastModifiedBy() {
    return lastModifiedBy;
}

public void setLastModifiedBy(AdminUser lastModifiedBy) {
    if (lastModifiedBy == null) {
        //ignore attempts to clear this field
        return;
        //throw new IllegalStateException("Null lastModifiedBy not allowed");
    }
        this.lastModifiedBy = lastModifiedBy;
    }

    public boolean isDeleted() {
        return deleted;
    }

    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

}
项目临时性接口

public interface ITemporalEntity {

    public DateTime getCreateDate();

    public void setCreateDate(DateTime createDate);

    public DateTime getLastModifiedDate();

    public void setLastModifiedDate(DateTime lastModifiedDate);

    public AdminUser getCreatedBy();

    public void setCreatedBy(AdminUser createdBy);

    public AdminUser getLastModifiedBy();

    public void setLastModifiedBy(AdminUser lastModifiedBy);

    public boolean isDeleted();

    public void setDeleted(boolean deleted);

}
错误堆栈

an assertion failure occurred (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: Subclass has to be binded after it's mother class: com.berwick.dal.TemporalEntity
23:11:29,486 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 87) MSC000001: Failed to start service jboss.persistenceunit."bds-core-1.0-SNAPSHOT.war#com.berwick.dal": org.jboss.msc.service.StartException in service jboss.persistenceunit."bds-core-1.0-SNAPSHOT.war#com.berwick.dal": org.hibernate.AssertionFailure: Subclass has to be binded after it's mother class: com.berwick.dal.TemporalEntity
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:198) [wildfly-jpa-21.0.0.Final.jar:21.0.0.Final]
My尝试解决此问题

@MappedSuperclass
添加到临时类 这使得这个错误消失了,但我得到了更多的错误

Duplicate generator name Individual_generator you will likely want to set the property hibernate.jpa.compliance.global_id_generators to false 
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:198) [wildfly-jpa-21.0.0.Final.jar:21.0.0.Final]

这个问题与链接线程中的问题非常相似。

编写要嵌入@target注释中的实体类名

   @Embedded
   @Target(TemporalEntity.class)
   private ITemporalEntity temporal;
   
   

您不需要通过创建嵌入do it的新对象来紧密耦合临时性。这个问题与链接线程中的问题非常相似。

编写要嵌入@target注释中的实体类名

   @Embedded
   @Target(TemporalEntity.class)
   private ITemporalEntity temporal;
   
   

您不需要通过创建嵌入的新对象来紧密耦合临时性,您是否尝试更改生成器名称?检查此线程,然后回答第二个问题:是的,我知道hibernate不支持继承,这就是为什么我创建一个接口ITemporalEntity,然后创建一个新实例并实现所有字段,如图所示@Embedded private TemporalEntity temporal=新的TemporalEntity();您是否尝试更改生成器名称?检查此线程并回答第二个问题:是的,我知道hibernate不支持继承,这就是为什么我创建一个接口ITemporalEntity,然后创建一个新实例并实现所有字段,如图所示@Embedded private TemporalEntity temporal=new TemporalEntity();谢谢您的回答,但是我可以通过“可能希望将hibernate.jpa.compliance.global_id_generators属性设置为false”来修复吗?我们可以使用“组合”或“继承”两种模式。有了“@embedded”和“@embeddeble”,您就使用了合成模式。我认为使用@MappedSuperclass就是在利用继承。继承带来了额外的问题。使用组合更好。我做了更改,但仍然得到相同的错误子类必须在其母类后绑定感谢您的回答,但我可以通过“可能希望将hibernate.jpa.compliance.global_id_generators属性设置为false”来修复此问题。我们可以使用“组合”或“继承”两种模式。有了“@embedded”和“@embeddeble”,您就使用了合成模式。我认为使用@MappedSuperclass就是在利用继承。继承带来了额外的问题。使用组合更好。我做了更改,但仍然得到相同的错误,子类必须在其母类之后绑定