Fix lob errors

This commit is contained in:
britea 2020-03-18 13:29:21 +01:00
parent 300f749144
commit e777f29585
2 changed files with 5 additions and 1 deletions

View file

@ -6,6 +6,8 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import javax.transaction.Transactional;
/**
* DeviceRepository acts as a superclass for the other repositories so to mirror in the database the
* class inheritance present among the various devices.
@ -20,6 +22,7 @@ public interface DeviceRepository<T extends Device> extends CrudRepository<T, Lo
* @param username a User's username
* @return an optional device, empty if none found
*/
@Transactional
@Query("SELECT d FROM Device d JOIN d.room r JOIN r.user u WHERE d.id = ?1 AND u.username = ?2")
Optional<T> findByIdAndUsername(Long id, String username);
@ -29,6 +32,7 @@ public interface DeviceRepository<T extends Device> extends CrudRepository<T, Lo
* @param username the User's username
* @return all devices of that user
*/
@Transactional
@Query("SELECT d FROM Device d JOIN d.room r JOIN r.user u WHERE u.username = ?1")
List<T> findAllByUsername(String username);
@ -38,6 +42,7 @@ public interface DeviceRepository<T extends Device> extends CrudRepository<T, Lo
* @param deviceId the device id
* @return a user object
*/
@Transactional
@Query("SELECT u FROM Device d JOIN d.room r JOIN r.user u WHERE d.id = ?1")
User findUser(Long deviceId);
}

View file

@ -125,7 +125,6 @@ public class Room {
* https://www.baeldung.com/java-base64-image-string
* https://docs.oracle.com/javase/8/docs/api/java/util/Base64.html
*/
@Lob
@Column(name = "image", columnDefinition = "TEXT")
private String image;