I have a prototype entity bean with multiple fields and 2 transient ones. Of these one is prototype as well and other is singleton.
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Entity
@Table(name = "tableA")
class A{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private String name;
@Autowired
@Transient
private CacheA cache; //Prototype bean for caching some calc results
@Autowired
@Transient
private ServiceA service; //Singleton service bean
}
Everything works until I try to read instance from database, because when Hibernate creates instance, Spring wont autowire any field.
Some additional info: I'm using CrudRepository and hibernate autoconfigured by spring-boot.
How do I properly solve such case? Is this intended behaviour, or should I make some additional configuration for hibernate to use spring context?