Fix LazyInitializationException and update hostname format

This commit is contained in:
hitanshu310 2026-02-16 00:38:23 +05:30
parent 3b43039a29
commit 94363b9429
5 changed files with 19 additions and 8 deletions

View File

@ -4,11 +4,21 @@ import com.hithomelabs.CFTunnels.Entity.Request;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Repository
public interface RequestRepository extends JpaRepository<Request, UUID> {
Page<Request> findByStatus(Request.RequestStatus status, Pageable pageable);
@Query("SELECT r FROM Request r JOIN FETCH r.mapping m JOIN FETCH m.tunnel JOIN FETCH r.createdBy LEFT JOIN FETCH r.acceptedBy")
List<Request> findAllWithDetails();
@Query("SELECT r FROM Request r JOIN FETCH r.mapping m JOIN FETCH m.tunnel JOIN FETCH r.createdBy LEFT JOIN FETCH r.acceptedBy WHERE r.id = :id")
Optional<Request> findByIdWithDetails(@Param("id") UUID id);
}

View File

@ -59,8 +59,9 @@ public class MappingRequestService {
return createRequest(mapping, user);
}
@Transactional(readOnly = true)
public List<Request> getAllRequests() {
return requestRepository.findAll();
return requestRepository.findAllWithDetails();
}
public User mapUser(OidcUser oidcUser){
@ -99,7 +100,7 @@ public class MappingRequestService {
@Transactional
public Request approveRequest(UUID requestId, User approver) {
Request request = requestRepository.findById(requestId)
Request request = requestRepository.findByIdWithDetails(requestId)
.orElseThrow(() -> new NoSuchElementException("Request not found"));
if (request.getStatus() != Request.RequestStatus.PENDING) {
@ -127,7 +128,7 @@ public class MappingRequestService {
@Transactional
public Request rejectRequest(UUID requestId, User rejecter) {
Request request = requestRepository.findById(requestId)
Request request = requestRepository.findByIdWithDetails(requestId)
.orElseThrow(() -> new NoSuchElementException("Request not found"));
if (request.getStatus() != Request.RequestStatus.PENDING) {
@ -145,7 +146,7 @@ public class MappingRequestService {
Tunnel tunnel = mapping.getTunnel();
String protocol = mapping.getProtocol().name().toLowerCase();
String service = protocol + "://" + SERVER_IP + ":" + mapping.getPort();
String hostname = mapping.getSubdomain() + "." + tunnel.getName() + ".hithomelabs.com";
String hostname = mapping.getSubdomain() + ".hithomelabs.com";
return new Ingress(service, hostname, null, null);
}
}

View File

@ -7,6 +7,6 @@ management.endpoint.health.show-details=always
logging.level.org.hibernate.SQL=DEBUG
debug=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.datasource.url=jdbc:postgresql://localhost:5432/cftunnel

View File

@ -7,6 +7,6 @@ spring.datasource.password=${POSTGRES_PASSWORD}
spring.datasource.driver-class-name=org.postgresql.Driver
# JPA Configuration
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect

View File

@ -7,6 +7,6 @@ spring.datasource.password=${POSTGRES_PASSWORD}
spring.datasource.driver-class-name=org.postgresql.Driver
# JPA Configuration
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect