Wel you could intercept the method which saves your product, check wether
ANY and NONE shipments are already present in the database and insert them
otherwise. In your 'normal' code for saving the product you replace the
final static objects by the ones persited in the database whenever ANY oder
NONE is selected.

But I think it's overpowered to use method interception in that case. I'd
just use DBunit to prepopulate the database with any data necessary. In my
experience these data increases as the application grows. ;-)

On Wed, Oct 8, 2008 at 6:13 PM, Luiz Fernando Rodrigues <[EMAIL PROTECTED]
> wrote:

> No, the table is not pre populated. I would like to avoid inserting data
> other way than through the application code.
> I do believe that inserting two entries is a good solution. But how to
> control that in the application code?
>
> Thanks for helping.
>
> Luiz Fernando
>
>
> 2008/10/8 Vincent Ramdhanie <[EMAIL PROTECTED]>
>
> Do you have your preferred ship table pre populated with data? In that case
>> why not add ANY and NONE as two entries rather than making them static final
>> objects. So the combo box will display all data in the preferred ship table
>> including ANY and NONE and there, you do not have to treat them differently.
>>
>> Just a thought.
>>
>> Vincent
>>
>>
>> On Wed, Oct 8, 2008 at 11:12 AM, Luiz Fernando Rodrigues <
>> [EMAIL PROTECTED]> wrote:
>>
>>> Hi there,
>>>
>>>  I'm mapping my application to a database usinf JPA tags. I'm with the
>>> following situation:
>>>
>>> I have a class Product which has an attribute preferedShip, from the
>>> class Ship.
>>> In the interface, the user chooses a ship from a combobox. The combo
>>> lists all the registered ships and two more options: ANY and NONE.
>>>
>>> I have modeled ANY and NONE as static final objects of the type Ship,
>>> because, like this I don't have to treat each case apart. Any and none are
>>> Ships them.
>>>
>>> Well, the problem is to persist this code. To save a product with
>>> preferedShip as ANY or NONE I will have to reference one of the two objects.
>>> But they are not persisted, because I modeled it as static final objects.
>>> If I map it to the database I'll have to hard code an id in the objects.
>>>
>>> Is this a good solution? Does anyone see any better solution?
>>>
>>> thanks,
>>> Luiz Fernando
>>>
>>
>>
>


-- 
-- 
Mit freundlichen Grüßen / With kind regards

Michael Dürgner

Reply via email to