• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate Mapping question

 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an entity Component with componentType as a field. This field is not persistable, its value will be set from outside (by caller).
My question is how should I handle it? If I mark it transient then its value will not be serialized, which I don't think serves the purpose. Its value must be serialized if object is serialized in J2ee environment and on deserialization that should come back. So what is the solution (what annotation should I use to mark it and its setter/getter)?



 
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you have to mark it as transient using an annotation @Transient from the javax.persistance package, what you are talking about is the transient modifier which has nothing to do with you case. for example you attribute should be like this.



this should solve your problems.



(peace)
 
Varun Chopra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I thought so. But I have read on some tutorials that if you do not want a field to be persisted then mark it with annotation @Transient or with Java Keyword 'transient'. It looks like any of them can be used. So the question is does @Transient behave similar to 'transient' or it's specific to Java Persistence and has nothing to do with Java Serialization? I am still trying to find clear distinction between them.
 
Omar Al Kababji
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well i am pretty sure that they have nothing to do with each others. However if you want to prove it for your self create a bean and set one of its attributes with a @Transient annotation then try to serialize it and then deserialize it back and check its attribute value (the one you marked as @Transient) you will see that it still have its same old value ;)


(peace)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic