forked from Abdulbari/sgeUpdated
Fix Backend error:
Error loading data: Exception while fetching data (/vmEmissionSummary) : org.hibernate.exception.SQLGrammarException: could not extract ResultSet
This commit is contained in:
@@ -22,7 +22,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class MainDataTableService extends BaseService<MainDataTable, MainDataTableRepo, MainDataTableCriteria, MainDataTableCriteriaSpec> {
|
public class MainDataTableService
|
||||||
|
extends BaseService<MainDataTable, MainDataTableRepo, MainDataTableCriteria, MainDataTableCriteriaSpec> {
|
||||||
|
|
||||||
@PersistenceContext
|
@PersistenceContext
|
||||||
private EntityManager entityManager;
|
private EntityManager entityManager;
|
||||||
@@ -48,34 +49,32 @@ public class MainDataTableService extends BaseService<MainDataTable, MainDataTab
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (projectId != null) {
|
if (projectId != null) {
|
||||||
whereConditions.add("p.id = decode(replace(:projectId, '-', ''), 'hex')");
|
whereConditions.add("v.project = :projectId");
|
||||||
}
|
}
|
||||||
|
|
||||||
String whereClause = whereConditions.isEmpty() ? "" :
|
String whereClause = whereConditions.isEmpty() ? "" : "WHERE " + String.join(" AND ", whereConditions) + " ";
|
||||||
"WHERE " + String.join(" AND ", whereConditions) + " ";
|
|
||||||
|
|
||||||
String sql = """
|
String sql = """
|
||||||
SELECT
|
SELECT
|
||||||
CAST(v.id AS VARCHAR) as vm_id,
|
CAST(v.id AS VARCHAR) as vm_id,
|
||||||
v.vm_name as vm_name,
|
v.vm_name as vm_name,
|
||||||
v.power as vm_power,
|
v.power as vm_power,
|
||||||
v.state as vm_status,
|
v.state as vm_status,
|
||||||
mdt.total_emission,
|
mdt.total_emission,
|
||||||
mdt.created_date,
|
mdt.created_date,
|
||||||
pm.name as physical_machine_name,
|
pm.name as physical_machine_name,
|
||||||
p.name as project_name,
|
v.project as project_name,
|
||||||
dc.data_center_name as datacenter_name,
|
dc.data_center_name as datacenter_name,
|
||||||
mdt.co2,
|
mdt.co2,
|
||||||
mdt.ch4,
|
mdt.ch4,
|
||||||
mdt.n2o
|
mdt.n2o
|
||||||
FROM main_data_table mdt
|
FROM main_data_table mdt
|
||||||
JOIN vm v ON mdt.vm_id = v.id
|
JOIN vm v ON mdt.vm_id = v.id
|
||||||
LEFT JOIN physical_machine pm ON v.physical_machine_id = pm.id
|
LEFT JOIN physical_machine pm ON v.physical_machine_id = pm.id
|
||||||
LEFT JOIN project p ON pm.project_id = p.id
|
LEFT JOIN data_center dc ON pm.data_center_id = dc.id
|
||||||
LEFT JOIN data_center dc ON p.data_center_id = dc.id
|
""" + whereClause + """
|
||||||
""" + whereClause + """
|
ORDER BY mdt.created_date DESC, v.vm_name
|
||||||
ORDER BY mdt.created_date DESC, v.vm_name
|
""";
|
||||||
""";
|
|
||||||
|
|
||||||
Query query = entityManager.createNativeQuery(sql);
|
Query query = entityManager.createNativeQuery(sql);
|
||||||
|
|
||||||
@@ -125,6 +124,7 @@ public class MainDataTableService extends BaseService<MainDataTable, MainDataTab
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts PostgreSQL hex format UUID to proper UUID format
|
* Converts PostgreSQL hex format UUID to proper UUID format
|
||||||
|
*
|
||||||
* @param hexUuid UUID in hex format (e.g., \x6205c18b8d1e4f0fa5154212fb44050b)
|
* @param hexUuid UUID in hex format (e.g., \x6205c18b8d1e4f0fa5154212fb44050b)
|
||||||
* @return UUID object
|
* @return UUID object
|
||||||
*/
|
*/
|
||||||
@@ -135,10 +135,10 @@ public class MainDataTableService extends BaseService<MainDataTable, MainDataTab
|
|||||||
// Insert hyphens to make it a proper UUID format
|
// Insert hyphens to make it a proper UUID format
|
||||||
// UUID format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
// UUID format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||||
String formatted = hex.substring(0, 8) + "-" +
|
String formatted = hex.substring(0, 8) + "-" +
|
||||||
hex.substring(8, 12) + "-" +
|
hex.substring(8, 12) + "-" +
|
||||||
hex.substring(12, 16) + "-" +
|
hex.substring(12, 16) + "-" +
|
||||||
hex.substring(16, 20) + "-" +
|
hex.substring(16, 20) + "-" +
|
||||||
hex.substring(20);
|
hex.substring(20);
|
||||||
return UUID.fromString(formatted);
|
return UUID.fromString(formatted);
|
||||||
} else {
|
} else {
|
||||||
// If it's already in proper format, parse directly
|
// If it's already in proper format, parse directly
|
||||||
|
|||||||
Reference in New Issue
Block a user