大家好,
我目前正在尝试理解,我的编码和实体模型有什么问题我使用hibernate 4.2来进行CRUD操作,只使用Generic DAO模式和带有级联ALL和orphanRemoval = true的带注释实体.我有DayPlan实体与DayToMany关系到DayPlanElement弱实体.该 DayPlanElement被保存到java.util.Set中.每个DayPlanElement都有一个属性"order".
该DayPlan也有一个实体一对多关系的人.实体Person保存到java.util中.清单.
该DayPlanElement具有一对多关系DayPlanElementEntry弱实体.java.util.Set用于保存.该人士实体也一对多关系DayPlanElementEntry弱实体.java.util.Set用于保存.该DayPlan,DayPlanElement和 人实体有ID,通过我的应用程序管理,为String.该DayPlanElementEntry弱实体具有复合编号:DayPlanElementEntryId与EmbeddedId注释,包含parentPersonId和dayPlanElementId.它
换句话说,想象一下,存在一个表,代表日计划.列是从0到24的小时数.行是人员,必须从日计划开始操作.每列都是DayPlanElement实体.每一行都是Person实体.每个单元格都是DayPlanElementEntry实体.
如果我只是添加到表新元素(也是人)并删除它(也从列表中删除它,然后调用DayPlanDAO.merge(dayPlan) - 我希望在级联和orphanRemoval) - 我没有问题.
只有当我尝试重新排序给定的人(只是删除java.util.List中的操作)和调用DayPlanDAO.merge(dayPlan)时,才会抛出以下异常:
Caused by: java.lang.IllegalStateException:
Error occurred while storing entity
[DayPlanElementEntry [getDayPlanMode()=NONE, getCompositeId()=DayPlanElementEntryId [parentPersonId=874c8eac-8796-478d-a4d5-dd011f7d6a4b, dayPlanElementId=ab683a25-633e-419e-89b6-4aef7829d4f6], hashCode=-2039940039]].
An entity copy
[org.hw.domain.DayPlanElementEntry#DayPlanElementEntryId [parentPersonId=874c8eac-8796-478d-a4d5-dd011f7d6a4b, dayPlanElementId=ab683a25-633e-419e-89b6-4aef7829d4f6]]
was already assigned to a different entity
[org.hw.domain.DayPlanElementEntry#DayPlanElementEntryId [parentPersonId=874c8eac-8796-478d-a4d5-dd011f7d6a4b, dayPlanElementId=ab683a25-633e-419e-89b6-4aef7829d4f6]].
at …Run Code Online (Sandbox Code Playgroud) 我使用@Autowired在POJO中注入一些服务.这些服务被注册为豆类.
如果一旦POJO由Spring管理(它也在Spring Config上注册为Bean),那么我对注入的服务没有任何问题.
但是,如果我创建"经典"POJO并通过"新"创建它,那么将不会注入任何服务.
我的问题:是否有可能配置Spring,实现@Autowired注入?
我使用由JavaConfig配置的Spring 4.0.3:
====
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.Ordered;
import org.springframework.http.MediaType;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.approval.ApprovalStore;
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.web.accept.ContentNegotiationManagerFactoryBean;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.ContentNegotiatingViewResolver;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
import com.tr.oauth.service.PhotoInfo;
import com.tr.oauth.service.PhotoService;
import com.tr.oauth.service.impl.PhotoServiceImpl;
import com.tr.oauth.service.oauth.ExtendedApprovalStoreUserApprovalHandler;
@Configuration
@EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
@Bean
public …Run Code Online (Sandbox Code Playgroud)