UserDO.java
@Entity
@Table(name = "UserDO")
public class UserDO {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long userId;
private boolean successfullyLinked;
private UserInformation userInformation;
}
UserInformation.java
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "address", "country_code", "currency_code", "email_address", "name", "phone" })
public class UserInformation {
@JsonProperty("address")
@Valid
private Address address;
@JsonProperty("country_code")
@NotNull
private String countryCode;
@JsonProperty("currency_code")
@Size(min = 3, max = 3)
private String currencyCode;
@JsonProperty("email_address")
@NotNull
private String emailAddress;
@JsonProperty("name")
@Valid
@NotNull
private Name name;
@JsonProperty("phone")
@Valid
private Phone phone;
}
我正在尝试将UserInformation POJO保存为Hibernate中UserDO的一部分。但是,当它作为Spring Boot应用程序的一部分运行时,我收到错误。以下是堆栈跟踪。
org.springframework.beans.factory.BeanCreationException:创建名称为' entityManagerFactory'的bean时出错在类路径资源中定义[org / springframework / boot / autoconfigure / orm / jpa / HibernateJpaAutoConfiguration.class]:调用init方法失败;嵌套异常是javax.persistence.PersistenceException:[PersistenceUnit:default]无法构建Hibernate SessionFactory
引起:javax.persistence.PersistenceException:[PersistenceUnit:default]无法构建Hibernate SessionFactory
引起:org.hibernate.MappingException:无法确定类型:com.paypal.marketplaces.vaas.api.models.UserInformation,在表:Tracking,for columns:[org.hibernate.mapping.Column(userInformation) )]
注意:UserInformation POJO非常复杂,其中包含其他对象和这些对象内的对象(依此类推)。任何不需要将UserInformation POJO显式映射到UserDO表的列的解决方案都是可取的。
任何帮助都将受到高度赞赏!
答案 0 :(得分:2)
持久性提供程序不知道该类,也不知道该怎么做。
我建议将其Embeddable
并可选择指定列名称:
import javax.persistence.Embeddalbe;
import javax.persistence.Column;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "address", "country_code", "currency_code", "email_address", "name", "phone" })
@Embeddable
public class UserInformation {
@JsonProperty("country_code")
@NotNull
@Column(name = "COUNTRY_CODE")
private String countryCode;
您必须为每个嵌套类重复此过程。
最后使用:
注释userInformation
@Embedded
private UserInformation userInformation;