Reputation: 11
I have legacy code with lots of relationships in one entity in Hibernate. Currently part of them are not using(there are null values for them in DB), but EntityManager query such as refresh() can employ lots of resources when try to load the useless relationships.
Manual entity contains nested Manual field, but joined by another column in the same table(template_id)
Table looks like:
| manual_id | .... | ....| template_id | ... |
--
> public class Manual implements Serializable
> ----
> ---
> @ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.MERGE,
> CascadeType.PERSIST, CascadeType.DETACH })
> @JoinColumn(name = "template_id")
> private Manual exTemplate;
in fact template_id is always null- so this relationship is useless.
How can I softly omit such relationships? the entity is core and simply removing of it - is risky.
I tried to use @Transient annotation, removing @ManyToOne and @JoinColumn from the field, but got such exception:
[ERROR] org.springframework.boot.context.embedded.tomcat.TomcatStarter
- Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'logFilter': Unsatisfied dependency expressed through field 'authService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'authService': Unsatisfied dependency expressed through field 'externalAuthService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'authServiceExternalImpl': Unsatisfied dependency expressed through field 'mqService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'rabbitMQService': Unsatisfied dependency expressed through field 'objectMapper'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'objectMapper' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.fasterxml.jackson.databind.ObjectMapper]: Factory method 'objectMapper' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'config' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.rest.core.config.RepositoryRestConfiguration]: Factory method 'config' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'repositories' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.repository.support.Repositories]: Factory method 'repositories' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'crmTaskGoodRepository': Cannot create inner bean '(inner bean)#787cddea' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#787cddea': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
Upvotes: 0
Views: 60
Reputation: 100
Simple remove the @JoinColumn(name = "template_id") here , as well as the template class also . have you removed the annotation in both the places and tried . My removing in both the places doesnt affect anything . Just remove it and try .
Upvotes: 0