web-app使用spring mvc + hibernate。我有一个实体人女巫有一套电话作为@CollectionTable
,我面临的问题是,每次我编辑一个人,记录的手机将加倍!
控制台
12:38:05.367 [http-nio-8080-exec-7] DEBUG org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'appDispatcherServlet' processing GET request for [/studyink/person/edit/1]
12:38:05.367 [http-nio-8080-exec-7] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /person/edit/1
12:38:05.370 [http-nio-8080-exec-7] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Returning handler method [public tn.alveodata.studyink.models.beans.JsonResponseBean tn.alveodata.studyink.controllers.PersonController.edit(java.lang.Long,java.util.Locale) throws tn.alveodata.studyink.exceptions.BusinessException]
12:38:05.371 [http-nio-8080-exec-7] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'personController'
12:38:05.371 [http-nio-8080-exec-7] DEBUG org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/studyink/person/edit/1] is: -1
12:38:05.372 [http-nio-8080-exec-7] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Creating new transaction with name [tn.alveodata.studyink.services.imps.PersonServiceImp.find]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
12:38:05.387 [http-nio-8080-exec-7] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Opened new EntityManager [SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
12:38:05.388 [http-nio-8080-exec-7] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@4d6b3bf5]
Hibernate: select person0_.id as id2_15_0_, person0_.about as about3_15_0_, person0_.civility as civility4_15_0_, person0_.email as email5_15_0_, person0_.email_tocken as email_to6_15_0_, person0_.first_name as first_na7_15_0_, person0_.last_name as last_nam8_15_0_, person0_.photo as photo9_15_0_, person0_.registration_number as registr10_15_0_, person0_.type as type1_15_0_, person0_.creation_date as creatio11_15_0_, person0_.update_date as update_12_15_0_, person0_.website as website13_15_0_, person0_.birth_country as birth_c14_15_0_, person0_.birth_date as birth_d15_15_0_, person0_.birth_place as birth_p16_15_0_, person0_.nationality as nationa17_15_0_, addresses1_.profile as profile1_0_1_, addresses1_.city as city2_0_1_, addresses1_.country as country3_0_1_, addresses1_.latitude as latitude4_0_1_, addresses1_.longitude as longitud5_0_1_, addresses1_.street as street6_0_1_, addresses1_.type as type7_0_1_, addresses1_.zip as zip8_0_1_, attachment2_.profile as profile8_1_2_, attachment2_.effective_date as effectiv2_1_2_, attachment2_.file as file3_1_2_, attachment2_.title as title4_1_2_, attachment2_.usage as usage5_1_2_, attachment2_.creation_date as creation6_1_2_, attachment2_.update_date as update_d7_1_2_, phones3_.profile as profile5_11_3_, phones3_.call_dialling as call_dia2_11_3_, phones3_.call_number as call_num3_11_3_, phones3_.type as type4_11_3_, resources4_.profile as profile1_13_4_, resources4_.resource as resource2_13_4_, socialnetw5_.profile as profile1_16_5_, socialnetw5_.type as type2_16_5_, socialnetw5_.url as url3_16_5_, socialnetw5_.creation_date as creation4_16_5_, socialnetw5_.update_date as update_d5_16_5_, followerco6_.student___id as student_4_6_6_, followerco6_.follower___id as follower3_6_6_, followerco6_.follower___id as follower3_6_7_, followerco6_.student___id as student_4_6_7_, followerco6_.type as type1_6_7_, followerco6_.visa_date as visa_dat2_6_7_, company7_.id as id2_15_8_, company7_.about as about3_15_8_, company7_.civility as civility4_15_8_, company7_.email as email5_15_8_, company7_.email_tocken as email_to6_15_8_, company7_.first_name as first_na7_15_8_, company7_.last_name as last_nam8_15_8_, company7_.photo as photo9_15_8_, company7_.registration_number as registr10_15_8_, company7_.type as type1_15_8_, company7_.creation_date as creatio11_15_8_, company7_.update_date as update_12_15_8_, company7_.website as website13_15_8_, company7_.legal as legal18_15_8_, company7_.tax_registration as tax_reg19_15_8_, company7_.taxable as taxable20_15_8_, company7_.trade_register as trade_r21_15_8_, identity8_.id as id1_8_9_, identity8_.card_number as card_num2_8_9_, identity8_.country as country3_8_9_, identity8_.effective_date as effectiv4_8_9_, identity8_.type as type5_8_9_, identity8_.creation_date as creation6_8_9_, identity8_.update_date as update_d7_8_9_ from profiles person0_ left outer join addresses addresses1_ on person0_.id=addresses1_.profile left outer join attachments attachment2_ on person0_.id=attachment2_.profile left outer join phones phones3_ on person0_.id=phones3_.profile left outer join resources resources4_ on person0_.id=resources4_.profile left outer join social_networks socialnetw5_ on person0_.id=socialnetw5_.profile left outer join follower_profiles followerco6_ on person0_.id=followerco6_.student___id left outer join profiles company7_ on followerco6_.follower___id=company7_.id left outer join identities identity8_ on person0_.id=identity8_.id where person0_.id=? and person0_.type='PERSON'
Hibernate: select followerd0_.follower___id as follower3_7_0_, followerd0_.student___id as student_4_7_0_, followerd0_.follower___id as follower3_7_1_, followerd0_.student___id as student_4_7_1_, followerd0_.type as type1_7_1_, followerd0_.visa_date as visa_dat2_7_1_, person1_.id as id2_15_2_, person1_.about as about3_15_2_, person1_.civility as civility4_15_2_, person1_.email as email5_15_2_, person1_.email_tocken as email_to6_15_2_, person1_.first_name as first_na7_15_2_, person1_.last_name as last_nam8_15_2_, person1_.photo as photo9_15_2_, person1_.registration_number as registr10_15_2_, person1_.type as type1_15_2_, person1_.creation_date as creatio11_15_2_, person1_.update_date as update_12_15_2_, person1_.website as website13_15_2_, person1_.birth_country as birth_c14_15_2_, person1_.birth_date as birth_d15_15_2_, person1_.birth_place as birth_p16_15_2_, person1_.nationality as nationa17_15_2_, identity2_.id as id1_8_3_, identity2_.card_number as card_num2_8_3_, identity2_.country as country3_8_3_, identity2_.effective_date as effectiv4_8_3_, identity2_.type as type5_8_3_, identity2_.creation_date as creation6_8_3_, identity2_.update_date as update_d7_8_3_ from follower_profiles followerd0_ inner join profiles person1_ on followerd0_.student___id=person1_.id left outer join identities identity2_ on person1_.id=identity2_.id where followerd0_.follower___id=?
Hibernate: select followerpe0_.student___id as student_4_7_0_, followerpe0_.follower___id as follower3_7_0_, followerpe0_.follower___id as follower3_7_1_, followerpe0_.student___id as student_4_7_1_, followerpe0_.type as type1_7_1_, followerpe0_.visa_date as visa_dat2_7_1_, person1_.id as id2_15_2_, person1_.about as about3_15_2_, person1_.civility as civility4_15_2_, person1_.email as email5_15_2_, person1_.email_tocken as email_to6_15_2_, person1_.first_name as first_na7_15_2_, person1_.last_name as last_nam8_15_2_, person1_.photo as photo9_15_2_, person1_.registration_number as registr10_15_2_, person1_.type as type1_15_2_, person1_.creation_date as creatio11_15_2_, person1_.update_date as update_12_15_2_, person1_.website as website13_15_2_, person1_.birth_country as birth_c14_15_2_, person1_.birth_date as birth_d15_15_2_, person1_.birth_place as birth_p16_15_2_, person1_.nationality as nationa17_15_2_, identity2_.id as id1_8_3_, identity2_.card_number as card_num2_8_3_, identity2_.country as country3_8_3_, identity2_.effective_date as effectiv4_8_3_, identity2_.type as type5_8_3_, identity2_.creation_date as creation6_8_3_, identity2_.update_date as update_d7_8_3_ from follower_profiles followerpe0_ inner join profiles person1_ on followerpe0_.follower___id=person1_.id left outer join identities identity2_ on person1_.id=identity2_.id where followerpe0_.student___id=?
12:38:05.417 [http-nio-8080-exec-7] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Initiating transaction commit
12:38:05.417 [http-nio-8080-exec-7] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Committing JPA transaction on EntityManager [SessionImpl(PersistenceContext[entityKeys=[EntityKey[tn.alveodata.studyink.models.entities.Person#1]],collectionKeys=[CollectionKey[tn.alveodata.studyink.models.entities.Self.socialNetworks#1], CollectionKey[tn.alveodata.studyink.models.entities.Self.addresses#1], CollectionKey[tn.alveodata.studyink.models.entities.Self.phones#1], CollectionKey[tn.alveodata.studyink.models.entities.Person.followerPersons#1], CollectionKey[tn.alveodata.studyink.models.entities.Self.resources#1], CollectionKey[tn.alveodata.studyink.models.entities.Person.followerCompanies#1], CollectionKey[tn.alveodata.studyink.models.entities.Person.followerd#1], CollectionKey[tn.alveodata.studyink.models.entities.Self.attachments#1]]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])]
Hibernate: delete from phones where profile=?
Hibernate: insert into phones (profile, call_dialling, call_number, type) values (?, ?, ?, ?)
Hibernate: insert into phones (profile, call_dialling, call_number, type) values (?, ?, ?, ?)
12:38:05.431 [http-nio-8080-exec-7] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Closing JPA EntityManager [SessionImpl(PersistenceContext[entityKeys=[EntityKey[tn.alveodata.studyink.models.entities.Person#1]],collectionKeys=[CollectionKey[tn.alveodata.studyink.models.entities.Self.socialNetworks#1], CollectionKey[tn.alveodata.studyink.models.entities.Self.addresses#1], CollectionKey[tn.alveodata.studyink.models.entities.Self.phones#1], CollectionKey[tn.alveodata.studyink.models.entities.Person.followerPersons#1], CollectionKey[tn.alveodata.studyink.models.entities.Self.resources#1], CollectionKey[tn.alveodata.studyink.models.entities.Person.followerCompanies#1], CollectionKey[tn.alveodata.studyink.models.entities.Person.followerd#1], CollectionKey[tn.alveodata.studyink.models.entities.Self.attachments#1]]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] after transaction
12:38:05.431 [http-nio-8080-exec-7] DEBUG org.springframework.orm.jpa.EntityManagerFactoryUtils - Closing JPA EntityManager
12:38:05.434 [http-nio-8080-exec-7] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor - Written [tn.alveodata.studyink.models.beans.JsonResponseBean@2c0f699d] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@37aa7ad5]
12:38:05.435 [http-nio-8080-exec-7] DEBUG org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'appDispatcherServlet': assuming HandlerAdapter completed request handling
12:38:05.436 [http-nio-8080-exec-7] DEBUG org.springframework.web.servlet.DispatcherServlet - Successfully completed request
Person.java是Profile.java的子类
Profile.java
@Id
protected Long id;
@Column(insertable = false, updatable = false)
protected String type;
private String firstName;
protected String lastName;
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name="phone", joinColumns=@JoinColumn(name="profile"))
protected Set<Phone> phones;
...
PersonController
@GetMapping(path = "/edit/{id}")
public @ResponseBody JsonResponseBean edit(@PathVariable Long id, Locale locale) throws BusinessException {
JsonResponseBean jsonResponse = new JsonResponseBean();
Person current = personService.find(id);
jsonResponse.setObject(current);
...
return jsonResponse;
}
PersonService
public Person find(Long id) {
return dao.find(id);
}
PersonDao的
public Person find(Long id) {
return em.find(Person.class, id);
}
请帮忙
这里是Phone.java
@Embeddable
public class Phone implements Serializable {
@Enumerated(EnumType.STRING)
private Type type;
private String callNumber;
...