我得到一个异常说“main”org.hibernate.MappingException:未知实体:com.with.annotations.AddressAsValueObject。但我在hibernate.cfg.xml中将此条目作为<mapping class="com.with.annotations.AddressAsValueObject">
。
@Embeddable
public class AddressAsValueObject {
//All attributes here..
}
@Entity
@Table (name="USER_WITH_V_ADDRESS")
public class UserDetailsWithAddressValueObject {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
@Column(name = "USER_ID")
private int id;
@Column(name = "USER_NAME")
private String name;
@Embedded
private AddressAsValueObject addressObj;
@Column(name = "USER_DOB")
private String dob;
}
UserDetailsWithAddressValueObject userDetailsWithAddressValueObject = new UserDetailsWithAddressValueObject();
userDetailsWithAddressValueObject.setName("XXX-WITH-ADDRESS");
userDetailsWithAddressValueObject.setDob("JUN6");
AddressAsValueObject addressValueObject = new AddressAsValueObject();
addressValueObject.setCity("PUNE");
addressValueObject.setStreet("XXXX");
addressValueObject.setPin("XXXXX");
userDetailsWithAddressValueObject.setAddressObj(addressValueObject);
session1.save(addressValueObject);
session1.save(userDetailsWithAddressValueObject);
我正在使用此映射异常。请帮我解决这个错误?
答案 0 :(得分:0)
您正在尝试保存AddressAsValueObject
的实例。但AddressAsValueObject
不是一个实体。这是一个可嵌入的课程。它无法单独保存。仅作为实际实体的一部分(嵌入式)。
删除对
的调用session1.save(addressValueObject);