Bill Gorder wrote:What is in the array and how is it being used?
possibilities are
1. It is an array of Entities that you want to save.
-In this case iterate over the array and save each entity.
2. You have an entity that you wish to save which itself contains an array of entities as one of its fields
- here I would use a collection like List or Set rather than an array.
3. You have an entity that you wish to save which itself contains an array of basic objects (like Strings) as one of its fileds
- Here is would still use a collection, but you could look at @ElementCollection.
Hope that helps.
Bill Gorder wrote:Ok from your description I am envisioning a table with one column and each row is one string in your array. Of course I doubt that is what you mean. Is the array of strings part of an object which is a persistent entity for example a list of phone numbers on a Person object. Hibernate is an ORM so usually you will have domain objects with relationships. If you help me understand these relationships I can probably give you better help mapping it correctly.
Bill Gorder wrote:Ok from your description I am envisioning a table with one column and each row is one string in your array. Of course I doubt that is what you mean.
Bill Gorder wrote:If there are no relationships I would not use an ORM. ORM''s solve the impedance mismatch problem (basically making object models and relational models play nice together). In your case you state that there is no relationship, in the database or the object model as far as I can see. I actually wonder what benefit you will gain storing this value as I am not sure how you will retrieve it or use it in a meaningful way. That said if you absolutely had to use hibernate for this you must create an Entity for it to be persistent.
It might look something like below for an auto incremented id and a voucher:
Now when you new up a MyEntity you would only set the voucher the id is auto generated when its persisted. You could iterate over an array or list of these MyEntity objects and save them to the database using either an EntityManager (JPA) or a Hibernate Session.
He does not suffer fools gladly. But this tiny ad does:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|