• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Mapping question

 
Varun Chopra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • 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)?



 
Omar Al Kababji
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic