Women in Technology

Hear us Roar



Article:
  Hibernate Your Data
Subject:   avoiding setter methods
Date:   2004-01-19 06:24:28
From:   anonymous2
hi,
i'm new to hibernate and this article gave me a great introduction to it.
i have a question: isn't it dangerous to have setter methods for all properties in the "business objects"?
for example, class OrderItem in the example presented in this article has a constructor that accepts an Order, a Product and an amount of products. the constructor decreases the Product's stock availability by the given amount, and sets the price of the order item accordingly. after an order item is created, you could, for some reason, call its "setAmount()" method. since this method doesn't adjust item's price and the product's stock availability, you could easily get get into serius trouble since the amount of products on the stock and the price of the item would be wrong.
i presume these methods are here becouse hibernate needs them to create objects load data from a database into them, so they are not meant to be used explicitly...
i'd like to know if there's an easy way to avoid these methods in the "business objects"? (other than "being careful and not use them int this way" :) )
Full Threads Newest First

Showing messages 1 through 1 of 1.

  • avoiding setter methods
    2004-01-19 15:00:51  epbernard [View]

    Either ask hibernate to use field instead of setter or use a private setter (Hibernate can handle it)