我有一个复杂的json文件,需要保存到Db“ mysql”,我正在使用hibernate,jpa 2,spring-boot。
我创建了模型类来将对象映射到pojos,但是由于我在休眠中不太好。我不太确定objs之间的关系。
这里是一个例子:
@Data
@Entity
@Table(name = "test_4_config")
public class Test_4 {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@JsonIgnore
private Long id;
private int sequenceTestNr;
private int betweenButtInterval;
private int repetitions;
private Sequence2 sequence;
@ElementCollection
@CollectionTable(name = "colors_test_4", joinColumns = @JoinColumn(name = "test_4_id"))
private List<String> colors= new ArrayList<>();
@ElementCollection
@CollectionTable(name = "images_test_4", joinColumns = @JoinColumn(name = "test_4_id"))
private List<Image> images= new ArrayList<>();
@ElementCollection
@CollectionTable(name = "btn2_test_4", joinColumns = @JoinColumn(name = "test_4_id"))
private List<Button2> buttons= new ArrayList<>();
}
Button2类
@Data
@Embeddable
public class Button2 {
private String background_color;
private boolean btnShow;
private Location location;
private String text_color;
private String text;
}
@Data
@Embeddable
public class Image {
private String src;
}
这些类嵌套在此类内:
@Data
@Entity
@Table(name = "configuration1")
public class ConfigTest {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@JsonIgnore
private Long id;
private Timer timer;
private TestTypes testtypes;
private int button_sequence;
private String language_template;
private KeyCodeToClick keycodeToClick;
@ElementCollection
@CollectionTable(name = "verifyKlaratTestObj", joinColumns = @JoinColumn(name = "config_test_id"))
private List<String> verifyKlaratTestObj;
@OneToOne(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
private Test_0 test_0;
@OneToOne(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
private Test_1 test_1;
@OneToOne(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
private Test_2 test_2;
@OneToOne(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
private Test_3 test_3;
@OneToOne(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
private Test_4 test_4;
@OneToOne(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
private Test_5 test_5;
@OneToOne(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
private Test_6 test_6;
@OneToOne(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
private Test_7 test_7;
@OneToOne(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
private Test_8 test_8;
@OneToOne(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
private Test_9 test_9;
@OneToOne(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
private Test_10 test_10;
@OneToOne(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
private Test_11 test_11;
@OneToOne(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
private Test_12 test_12;
}
这是错误:
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not determine type for: java.util.List, at table: test_4_config, for columns: [org.hibernate.mapping.Column(button)]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:402) ~[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) ~[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
... 21 common frames omitted