我正在运行Hibernate 4.2.6.Final / JPA2,并尝试具有@Embeddable对象的@ElementCollection列表,这些对象本身包含String的@ElementCollection列表。
但是,hibernate在尝试实例化EntityManager时抛出ConcurrentModificationException,我根本不了解。
如果我在List<Address>
中注释掉我的User
,则一切运行正常。同样,如果我注释掉List<String> street
中的Address
,则所有内容也会正常启动。我假设它与具有自己的嵌入式ElementCollection的ElementCollection有关。
public class User {
@TableGenerator( name="UUIDGenerator", pkColumnValue="user_id", table="uuid_generator", allocationSize=1)
@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator="UUIDGenerator")
@Column(name = "id")
private Long id;
/**
* Login username
*/
@NotNull
private String username;
/**
* Password in encrypted format
*/
private String password;
/**
* Address
*/
@Valid
@ElementCollection(fetch=FetchType.LAZY)
@CollectionTable(name="user_address", joinColumns=@JoinColumn(name = "user_id", referencedColumnName = "id"))
@OrderColumn
private List<Address> address;
// getters and setters omitted for brevity
}
@Embeddable
public class Address {
/**
* Multiple street lines allowable
*/
@NotBlank
@ElementCollection(targetClass=String.class, fetch=FetchType.LAZY)
@CollectionTable( joinColumns=@JoinColumn(name = "address_id", referencedColumnName = "id"))
@OrderColumn
private List<String> street;
/**
* City
*/
private String city;
/**
* State/Province
*/
private String state;
/**
* Country
*/
private String country;
// getters and setters omitted for brevity
}
Caused by: java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:859)
at java.util.ArrayList$Itr.remove(ArrayList.java:845)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1633)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1390)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1777)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:899)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:76)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:288)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)
... 40 more
我是否不允许嵌入式类具有自己的
@ElementCollection
?这是不允许的吗?否则我该怎么做? 最佳答案
已经向Hibernate开发人员报告了此问题,尚未计划修复!抱歉。请参见https://hibernate.atlassian.net/browse/HHH-4313。