我收到以下错误:
object references an unsaved transient instance - save the transient instance before flushing: com.project.outer.dataobject.AddressIdentificationType; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.project.outer.dataobject.AddressIdentificationType
在网上看了一会儿后,我有点理解错误了,但是所有在线错误通常发生在两个需要添加的表(例如 OneToMany)之间的关系中,@OneToMany(cascade = Cascade.ALL)
但我没有这个,所以我不知道出了什么问题,有没有人知道?
地址识别类型.js
Ext.apply(AddressIdentificationType, {
valueProvider: {
getValues: AddressIdentificationTypeService.getAddressIdentificationTypes
},
地址识别类型.java
@Entity
@DataTransferObject(params={
@Param(name = "match", value = "com.project.outer.dataobject.AddressIdentificationType"),
@Param(name = "javascript", value = "AddressIdentificationType")})
public class AddressIdentificationType extends BaseEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long addressIdentificationTypeId;
@Column(length = 250, nullable=false)
private String description;
@Enumerated(EnumType.STRING)
@Column(length = 20)
private Region region;
public AddressIdentificationType() {
}
@RemoteProperty
public Long getAddressIdentificationTypeId() {
return addressIdentificationTypeId;
}
public void setAddressIdentificationTypeId(Long addressIdentificationTypeId) {
this.addressIdentificationTypeId = addressIdentificationTypeId;
}
@RemoteProperty
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
protected Long getId() {
return addressIdentificationTypeId;
}
地址识别类型服务.java
@Secured(value={"ROLE_GENERAL"})
@RemoteMethod
public List<IdentificationType> getAddressIdentificationTypes(Region region) {
if (region == null) {
region = Region.France;
}
return repository.getData(NamedQuery.AddressIdentificationTypePropertySelection, region);
}
如果需要查看更多代码,只需要求添加它,尽量使问题尽可能简短
编辑 - 基础实体
BaseEntity.java
@MappedSuperclass
public abstract class BaseEntity implements Cloneable {
@Transient
private String internalUUID;
@Version
@Column(columnDefinition = "int default 0")
protected Integer version;
@Column(length = 50)
protected String modifiedBy;
@Override
public int hashCode() {
return getUUID().hashCode();
}
@Override
public boolean equals(Object o) {
return (o == this || (o instanceof BaseEntity && getUUID().equals(((BaseEntity) o).getUUID())));
}
private String getUUID() {
// use the internalUUID if it has been set, otherwise create-->persist-->compare sequence will not work.
//
if (internalUUID != null) {
return internalUUID;
}
if (getId() != null) {
return getId().toString();
}
if (internalUUID == null) {
internalUUID = randomUUID().toString();
}
return internalUUID;
}
protected abstract Object getId();
//protected abstract void setId(Object obj);
protected BaseEntity clone() throws CloneNotSupportedException {
BaseEntity object = CloneMap.get(this.getClass().getName() + ":" + this.getId());
if (object != null) {
return object;
}
BaseEntity obj = (BaseEntity)super.clone();
obj.version = 0;
try {
Field field = getIdField(obj.getClass());
if (field != null) {
field.setAccessible(true);
field.set(obj, null);
}
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
CloneMap.put(this.getClass().getName() + ":" + this.getId(), obj);
return obj;
}
private static Field getIdField(Class clazz) {
try {
String name = clazz.getName();
name = name.substring(name.lastIndexOf(".") + 1);
return clazz.getDeclaredField(name.substring(0, 1).toLowerCase() + name.substring(1) + "Id");
} catch (NoSuchFieldException e) {
if (clazz.getSuperclass() == null) {
return null;
}
return getIdField(clazz.getSuperclass());
}
}
private static Field getField(Class clazz, String propertyName) {
try {
return clazz.getDeclaredField(propertyName);
} catch (NoSuchFieldException e) {
if (clazz.getSuperclass() == null) {
return null;
}
return getField(clazz.getSuperclass(), propertyName);
}
}
protected BaseEntity clone(Agent agent) throws CloneNotSupportedException {
BaseEntity obj = clone();
try {
Field field = getField(obj.getClass(), "agent");
if (field != null) {
field.setAccessible(true);
field.set(obj, agent);
}
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return obj;
}
protected <T extends BaseEntity> List<T> clone(List<T> list, Agent agent) throws CloneNotSupportedException {
List<T> newList = new ArrayList<T>();
for (T e: list) {
newList.add((T)e.clone(agent));
}
return newList;
}
protected <T extends BaseEntity> Set<T> clone(Set<T> list, Agent agent) throws CloneNotSupportedException {
Set<T> newList = new HashSet<T>();
for (T e: list) {
newList.add((T)e.clone(agent));
}
return newList;
}
}