@Immutable

Reference: @Immutable in Hibernate

@Immutable ์ด๋ž€?

  • ํ•ด๋‹น annotation์„ Entity ์— ์ถ”๊ฐ€ํ•˜๋ฉด, update๊ฐ€ ์ž‘๋™ํ•˜์ง€ ์•Š๋Š”๋‹ค

  • Collection ์— ์ถ”๊ฐ€ํ•˜๋ฉด, add & delete ์ž‘๋™ํ•˜์ง€ ์•Š๋Š”๋‹ค

@Immutable annotation์„ ์ถ”๊ฐ€ํ–ˆ์„ ๋•Œ ๋‹ฌ๋ผ์ง€๋Š” ๋™์ž‘

  • INSERT

    • ๋‹ฌ๋ผ์ง„ ์ ์ด ์—†๋‹ค

  • UPDATE

    • Hibernate๋Š” exception์„ ์ผ์œผํ‚ค์ง€ ์•Š๊ณ  ๊ทธ๋ƒฅ UPDATE ์ž‘์—… ์‹คํ–‰์„ ๋ฌด์‹œํ•œ๋‹ค

    • exception์ด ๋ฐœ์ƒํ•˜๊ฒŒ ํ•˜๋ ค๋ฉด, ๋”ฐ๋กœ ์„ค์ •์ด ํ•„์š”ํ•˜๋‹ค

  • DELETE

    • ๋‹ฌ๋ผ์ง„ ์ ์ด ์—†๋‹ค

์ฃผ์˜ํ•  ์ 

  • @Immutable ์—”ํ‹ฐํ‹ฐ๋Š” ์—ฌ์ „ํžˆ JPQL์ด๋‚˜ Criteria๋กœ ์—…๋ฐ์ดํŠธ ๊ฐ€๋Šฅํ•˜๋‹ค

  • but, 5.2.17๋ถ€ํ„ฐ๋Š” ์—…๋ฐ์ดํŠธ๋ฅผ ๋ง‰์•˜์œผ๋‚˜ WARNING๋งŒ ๋‚จ๊ธด๋‹ค

    • ์—ฌ๊ธฐ์— ์˜ค๋ฅ˜๊นŒ์ง€ ๋ฐœ์ƒ์‹œํ‚ค๋ ค๋ฉด ์•„๋ž˜ property๋ฅผ ์„ค์ •ํ•˜๋ฉด ๋œ๋‹ค

      hibernate.query.immutable_entity_update_query_handling_mode=exception

Last updated