0

I have following piece of code..

  1. working fine (staffTbl is not getting fetch lazily) @OneToOne(fetch=FetchType.LAZY) @JoinColumns({@javax.persistence.JoinColumn(name="inst_id", referencedColumnName="inst_id", insertable=false, updatable=false), @javax.persistence.JoinColumn(name="staff_id", referencedColumnName="staff_id", insertable=false, updatable=false)}) private StaffTbl staffTbl;

  2. but when I made this transient its always fetching null: @OneToOne(fetch=FetchType.LAZY) @JoinColumns({@javax.persistence.JoinColumn(name="inst_id", referencedColumnName="inst_id", insertable=false, updatable=false), @javax.persistence.JoinColumn(name="staff_id", referencedColumnName="staff_id", insertable=false, updatable=false)}) private transient StaffTbl staffTbl;

Is there any mistake?

(I'm using Hibernate 3, with JBoss 6.1)

LittleBobbyTables - Au Revoir
  • 32,008
  • 25
  • 109
  • 114
Vikash Tiwari
  • 113
  • 1
  • 10
  • It's the first time I see transient as a key word, but nonetheless - isn't that what you would expect? Transient means that the field should have no connection to the database. What is the problem you're trying to solve? – Deltharis Oct 31 '14 at 12:42

2 Answers2

1

Is there any mistake?

if a field has marked as transient, it means they are not part of the persistent state of the entity.

Solution:

change to:

private StaffTbl staffTbl;
Abhishek Nayak
  • 3,732
  • 3
  • 33
  • 64
  • I have seen you have answered many tough questions in spring.Please answer mine here http://stackoverflow.com/questions/28577325/how-to-run-2-tasks-separately –  Feb 18 '15 at 08:00
0

transient as a java keyword means that this field should be ignored when the object is serialized, so you probably are seeing effects of this. The question is what are you trying to achieve?

If you meant to mark staffTbl as transient in the context of Hibernate, you should have annotated it with @Transient, but you will have to set its value then, since it won't come from the database and you can expect more nulls.

Predrag Maric
  • 23,938
  • 5
  • 52
  • 68