title: How to autowire a transient attribute?
body: <p>I have an Entity for example Employee that contains a @Transient Object Salary which will be derived from a related table/Entity DailyTimeRecord (DTR). DTR object data retrieval uses Joins and it is also autowired in the Employee object. The list of DTR objects will be the basis in computing the value of the Salary Object.</p>
  
  <p>I found here [1]: <a href="https://stackoverflow.com/questions/19896870/why-is-my-spring-autowired-field-null">Why is my Spring @Autowired field null?</a> that using <code>new</code> keyword should be avoided, and let IoC Container create objects. In addition, I want to avoid using <code>new</code> keyword to minimize the coupling of my codes and ensure future compatibility and support scalability as much as possible. Therefore, I have interface Salary and implemented by a SalaryImpl class.</p>
  
  <p>But Each time I tried to run the codes the autowired on a transient attribute Salary, it is always null. And I found the root cause here [2]: <a href="https://stackoverflow.com/questions/46986778/how-to-populate-transient-field-in-jpa">How to populate @Transient field in JPA?</a> that Transient will always be null in JPA.</p>
  
  <p>How will I ever create a object that avoiding the use of <code>new</code> keyword while it is a transient attribute?</p>
  
  <p>Entity Class</p>
  
  <pre><code>   @Entity
     Class Employee implements Serializable {
            //Attributes from DB here
  
            @OneToMany
            @JoinColumn(name="empNumber", referencedColumnName = "empNumber")
            private List&lt;DTR&gt; dtr;
  
            @Autowired
            @Transient
            private Salary salary;
  
            //getters ang setters here
  
            public double computeSalary(){
  
            }
     }
  </code></pre>
  
  <p>Interface of Salary</p>
  
  <pre><code>   public interface Salary {
  
            public double computeSalary(List&lt;Benefit&gt; benefits, List&lt;Deduction&gt; deductions);
  
     }
  </code></pre>
  
  <p>Base/Implementation class of interface salary</p>
  
  <pre><code>   @Service
     public class SalaryImpl implements Salary, Serializable {
  
            //other attributes here
  
            //getter and setters
  
            //other methods
  
            @Override
            public double computeSalary(List&lt;Benefit&gt; benefits, List&lt;Deduction&gt; deductions){
                   return 0;
            }
     }
  </code></pre>