Last active
March 26, 2023 01:10
-
-
Save railroadman/b8d5fab3c2c6d290f7de9d7caad16f6a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@NamedNativeQuery( | |
name = "getTenders", | |
query = "SELECT t.id, t.created_at, CONCAT(u.first_name, ' ' , u.last_name) as created_by, t.modified_at, CONCAT(u2.first_name, ' ' , u2.last_name) as modified_by, t.tenders_abbreviation, t.tenders_full_name FROM abc.tenders v\n" + | |
"LEFT JOIN abc.users u on u.id = v.created_by LEFT JOIN rbac.users u2 on u2.id = v.modified_by", | |
resultSetMapping = "tendersMappings" | |
) | |
@SqlResultSetMapping(name = "tendersMappings", entities = { | |
@EntityResult(entityClass = TendersEntity.class, fields = { | |
@FieldResult(name = "id", column = "id"), | |
@FieldResult(name = "created_at", column = "created_at"), | |
@FieldResult(name = "modified_at", column = "modified_at"), | |
@FieldResult(name = "tenders_abbreviation", column = "tenders_abbreviation"), | |
@FieldResult(name = "tenders_full_name", column = "tenders_full_name"), | |
@FieldResult(name = "created_by", column = "created_by"), | |
@FieldResult(name = "modified_by", column = "modified_by") | |
}) | |
}) | |
@Entity | |
@Table(name = "tenders", schema = "abc") | |
public class TendersEntity { | |
private static final long serialVersionUID = 1L; | |
@Id | |
private Integer id; | |
@Column(name = "created_at") | |
private String created_at; | |
@Column(name = "created_by") | |
private String created_by; | |
@Column(name = "modified_at") | |
private String modified_at; | |
@Column(name = "modified_by") | |
private String modified_by; | |
@Column(name = "tenders_abbreviation") | |
private String tenders_abbreviation; | |
@Column(name = "tenders_full_name") | |
private String tenders_full_name; | |
public TendersEntity() {} | |
// setters and getters | |
//DAO class | |
@Repository | |
@Transactional | |
public class TendersDaoImpl implements TendersDao { | |
@Autowired | |
EntityManager manager; | |
@Override | |
public List<TendersEntity> getVendors() { | |
List<TendersEntity> dataList = new ArrayList<>(); | |
Query query = manager.createNamedQuery("getTenders"); | |
try { | |
dataList.addAll(query.getResultList()); | |
} catch (Exception ex) { | |
…….// exception code | |
} | |
return dataList; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment