@@ -111,6 +111,7 @@ public PlayerDTO create(PlayerDTO playerDTO) {
111111 *
112112 * @return a list of all players (empty list if none found)
113113 */
114+ @ Transactional (readOnly = true )
114115 @ Cacheable (value = "players" )
115116 public List <PlayerDTO > retrieveAll () {
116117 return playersRepository .findAll ()
@@ -128,6 +129,7 @@ public List<PlayerDTO> retrieveAll() {
128129 * @param id the UUID primary key (must not be null)
129130 * @return the player DTO if found, null otherwise
130131 */
132+ @ Transactional (readOnly = true )
131133 @ Cacheable (value = "players" , key = "#id" , unless = "#result == null" )
132134 public PlayerDTO retrieveById (UUID id ) {
133135 return playersRepository .findById (id )
@@ -144,6 +146,7 @@ public PlayerDTO retrieveById(UUID id) {
144146 * @param squadNumber the squad number to retrieve (jersey number, typically 1-99)
145147 * @return the player DTO if found, null otherwise
146148 */
149+ @ Transactional (readOnly = true )
147150 @ Cacheable (value = "players" , key = "'squad-' + #squadNumber" , unless = "#result == null" )
148151 public PlayerDTO retrieveBySquadNumber (Integer squadNumber ) {
149152 return playersRepository .findBySquadNumber (squadNumber )
@@ -163,6 +166,7 @@ public PlayerDTO retrieveBySquadNumber(Integer squadNumber) {
163166 * @param league the league name to search for (must not be null or blank)
164167 * @return a list of matching players (empty list if none found)
165168 */
169+ @ Transactional (readOnly = true )
166170 public List <PlayerDTO > searchByLeague (String league ) {
167171 return playersRepository .findByLeagueContainingIgnoreCase (league )
168172 .stream ()
@@ -192,6 +196,11 @@ public List<PlayerDTO> searchByLeague(String league) {
192196 public boolean update (Integer squadNumber , PlayerDTO playerDTO ) {
193197 log .debug ("Updating player with squad number: {}" , squadNumber );
194198
199+ if (squadNumber == null ) {
200+ log .warn ("Cannot update player - squad number is null" );
201+ return false ;
202+ }
203+
195204 return playersRepository .findBySquadNumber (squadNumber )
196205 .map (existing -> {
197206 Player player = mapFrom (playerDTO );
0 commit comments