java - Storing Objects in columns using Hibernate JPA -


Is it possible to store some things that are only using one table? Now, who comes into hibernation, he will make two applause, one for the family and one for the other. I want family members to serial in the database in the database.

  @Entity (name = "family") class family {Private last list & lt; Person & gt; Family members; } Class person {string first name, last name; Old age; }  

This is a terrific design and I'm not really recommending it ( You should just create another table) but this is possible.

First of all, you have to use a byte [] attribute to capture the sequence of those people's list, which will be stored in a blob in the database. Therefore, it annotate the recipient with @LOB (I will create recipient and setter personal to get them) Then, returning the "fake" recipient and sender or list & lt; Person & gt; Set to byte [] . In the sample given below, I am using Commons Lang (if you do not want to import this library, you can provide auxiliary class) to fly by byte [] Serialize / disassemble @Transcient will try to make up "fake" the recipient to be field do not forget or hibernation to characterize (and fail because it will not be able to determine the type of List < / Code>).

@Entity (name = "family") class family serializable {// ... private byte [] Family Marshers Asbetter; Public Family () {} @ Lbb @ Column (name = "member", length = Puarnank.amaks_avian - 1) private byte [] getFamilyMembersAsByteArray () Memberasebaitarere family returned to highlight {//; } Private void Setfamilimmberasbaitarere ((byte [] Family Memberasbaitare () {// not exposed Yhkfamlimomberjbetarere = family Sdasyabbaitarere;} @ Transiynt Public List & lt; person & gt; meet family mailers () (return (lt; person & gt ;) SerializationUtilskdeserialize (family Srmiconsbitearere);} public void set participants (list family members) {Yhkfamli Mmbers Sbitaare = serialization Util Ksiriyalaij ((Siriyljbl) family member);}}

man class Siriylaijhebl and a real serialVersionUID To add (I'm just showing a default here):

  public class person serialjazal {personal constant last long serial VersionUID = 1L; // ... private string first name, last name ; Private in the age;}  

But let me insist, this is a terrific design and it's great Be delicate (change man can be re-BLOB content to avoid Deserialization issues to sacrifice to "migrate" and it will be painful, you should really rethink this idea and Instead, the other table should be used for person (or why do not you use the database).


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -