-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Why does load() method goes to db immediately?
PostPosted: Mon Jul 01, 2013 9:36 am 
Newbie

Joined: Wed Jun 19, 2013 8:38 am
Posts: 2
Hello!

I have many-to-one relationship between Answer and Topic. My Answer looks as :
Code:
@Entity
@Table(name = DataBaseConstants.ANSWER_TABLE, catalog = DataBaseConstants.DBCATALOG, schema = "")
@XmlRootElement
@Access(AccessType.PROPERTY)
public class Answer {
        @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   @Column(name = DataBaseConstants.ANSWER_ID, nullable = false, updatable = false,            insertable = false)
   public Long getAnswer_id() {
      return answer_id;
   }

        @Version
   @Column(name = "OPTLOCK")
   public Long getVersion() {
      return version;
   }
       @Size(max = 21000)
   @Column(name = "content", columnDefinition = "VARCHAR")
   public String getContent() {
      return content;
   }

   @NotNull(message = "{Post_rate_notnull}")
   @Column(name = "rate")
   public Integer getRate() {
      return rate;
   }

   @NotNull(message = "{Post_date_notnull}")
   @Temporal(TemporalType.TIMESTAMP)
   @Column(name = "[PUBLISH_DATE]")
   public Date getPublish_date() {
      return publish_date;
   }
       @NotNull
   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "topic", referencedColumnName = "topic_id", nullable = false)
   public Topic getTopic() {
      return topic;
   }
       @NotNull
   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "user", referencedColumnName = "user_id")
   @NotFound(action = NotFoundAction.IGNORE)
   public JuniorUser getUser() {
      return user;
   }

Answer has hashcode and equals based on answer_id. There is no toString().
The problem is when I call method load() to get hibernate proxy of Answer , it loads immediately all Answer's and Topic's and JuniorUser's properties.
Code:
currentSession().load(Answer.class,1);

What causes hibernate to load everything immediately?
BTW, I set breakpoint just after this method is called and see all queries generated by hibernate in my console.

Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.