Within Industry 4.0, efficient fault diagnosis plays a pivotal role in predictive maintenance of industrial machinery. However, the challenge lies in the significant domain shift between the source (training) and target (testing) domains, which hampers the application of machine learning in engineering practice. Several approaches based on transfer learning have been proposed to cope with the lack of training data in the target domain and the related domain adaptation challenges. Those approaches leverage the knowledge from similar source domains, including related real-world applications or lab machines. Unfortunately, access to sufficient faulty data from such source domains is often restricted due to insufficient history of faults in real machines, as well as difficulties to get labeled datasets from lab machines, which is time-consuming and sometimes unfeasible. To tackle those issues, this paper proposes a novel diagnostic framework integrating digital twins and transfer learning to mitigate the limitations posed by insufficient training datasets and domain discrepancies. By leveraging digital twins, training datasets are generated as the source domain, while introducing a model update strategy based on parameter sensitivity analysis to enhance adaptability. In addition, the partial transfer diagnostic model, incorporating a double-layer attention mechanism, enables to cope with data distribution discrepancies between digital twins and real machines, as well as inconsistencies in label spaces across domains. The diagnostic framework is validated on an industrial rotating machine case study, where faulty behaviors originated by defects on the inner race, outer race, and ball of the bearing are considered. Real data from two publicly available datasets are leveraged. The results of the experimental analysis have been compared with state-of-the-art methodologies: the proposed approach is able to improve the diagnostic accuracy by over 11% in the specific case study. Therefore, the approach can effectively increase equipment reliability, optimize maintenance, and enhance operational efficiency.