我使用的是hibernate版本5.3.18.final,但是审计表的嵌入对象存在问题
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing column [createDate] in table [audit.Address_AUD]
这是完整的代码
@Audited
@Entity
public class Address {
@Id
@Column(name = "address_id")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "Address_generator")
@SequenceGenerator(name = "Address_generator", initialValue = 1, allocationSize = 1, sequenceName = "address_sequence")
private Long addressId;
@Column(name = "address")
private String address;
@Version
@Column(nullable = false)
private Long version;
@ManyToMany(mappedBy="addresses")
private List<AddressGroup> addressGroups;
public Long getAddressId() {
return addressId;
}
public void setAddressId(Long addressId) {
this.addressId = addressId;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Embedded
private TemporalEntity temporal;
public TemporalEntity getTemporal() { return temporal; }
public void setTemporal(TemporalEntity temporal) { this.temporal = temporal; }
public List<AddressGroup> getAddressGroups() {
return addressGroups;
}
public void setAddressGroups(List<AddressGroup> addressGroups) {
this.addressGroups = addressGroups;
}
}
@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;
}
}
错误日志
18:58:48,265 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 28) 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": javax.persistence.PersistenceException: [PersistenceUnit: com.berwick.dal] Unable to build Hibernate SessionFactory
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:198) [wildfly-jpa-21.0.0.Final.jar:21.0.0.Final]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:128) [wildfly-jpa-21.0.0.Final.jar:21.0.0.Final]
at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.8.0_221]
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:659) [wildfly-elytron-security-manager-1.13.1.Final.jar:1.13.1.Final]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:213) [wildfly-jpa-21.0.0.Final.jar:21.0.0.Final]
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35) [jboss-threads-2.1.1.Final.jar:2.1.1.Final]
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at java.lang.Thread.run(Thread.java:748) [rt.jar:1.8.0_221]
at org.jboss.threads.JBossThread.run(JBossThread.java:513) [jboss-threads-2.1.1.Final.jar:2.1.1.Final]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: com.berwick.dal] Unable to build Hibernate SessionFactory
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1327) [hibernate-core-5.3.18.Final.jar:5.3.18.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1253) [hibernate-core-5.3.18.Final.jar:5.3.18.Final]
at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:170) [wildfly-jpa-21.0.0.Final.jar:21.0.0.Final]
... 10 more
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing column [createDate] in table [audit.Address_AUD]
at org.hibernate.tool.schema.internal.AbstractSchemaValidator.validateTable(AbstractSchemaValidator.java:136) [hibernate-core-5.3.18.Final.jar:5.3.18.Final]
at org.hibernate.tool.schema.internal.GroupedSchemaValidatorImpl.validateTables(GroupedSchemaValidatorImpl.java:42) [hibernate-core-5.3.18.Final.jar:5.3.18.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaValidator.performValidation(AbstractSchemaValidator.java:89) [hibernate-core-5.3.18.Final.jar:5.3.18.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaValidator.doValidation(AbstractSchemaValidator.java:68) [hibernate-core-5.3.18.Final.jar:5.3.18.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:191) [hibernate-core-5.3.18.Final.jar:5.3.18.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72) [hibernate-core-5.3.18.Final.jar:5.3.18.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:310) [hibernate-core-5.3.18.Final.jar:5.3.18.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:467) [hibernate-core-5.3.18.Final.jar:5.3.18.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1250) [hibernate-core-5.3.18.Final.jar:5.3.18.Final]
... 12 more
18:58:48,277 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 1) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "bds-core-1.0-SNAPSHOT.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"bds-core-1.0-SNAPSHOT.war#com.berwick.dal\"" => "javax.persistence.PersistenceException: [PersistenceUnit: com.berwick.dal] Unable to build Hibernate SessionFactory
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: com.berwick.dal] Unable to build Hibernate SessionFactory
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing column [createDate] in table [audit.Address_AUD]"}}
18:58:48,280 ERROR [org.jboss.as.server] (management-handler-thread - 1) WFLYSRV0021: Deploy of deployment "bds-core-1.0-SNAPSHOT.war" was rolled back with the following failure message:
{"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"bds-core-1.0-SNAPSHOT.war#com.berwick.dal\"" => "javax.persistence.PersistenceException: [PersistenceUnit: com.berwick.dal] Unable to build Hibernate SessionFactory
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: com.berwick.dal] Unable to build Hibernate SessionFactory
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing column [createDate] in table [audit.Address_AUD]"}}
1条答案
按热度按时间ercv8c1e1#
在我的例子中,我只需要将名称添加到与字段名称匹配的列中
name="create_date"
```@Embeddable
public class TemporalEntity {