-->
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: @manytoone left outer join problem
PostPosted: Tue Dec 19, 2006 12:37 pm 
Newbie

Joined: Tue Dec 19, 2006 11:54 am
Posts: 1
Hi Everyone,

I have many-to-one unidirectional relationship between two objects as follows:

Code:
@Entity
@Table(name = "A")
public class A implements Serializable {

  private Long id;

  private B bObject;

  @Id
  public Long getId() {
    return id;
  }

  public void setId(Long _id) {
    id = _id;
  }

  @ManyToOne
  @JoinColumn(name = "a_id", insertable = false, updatable = false, nullable = true)
  public B getBObject() {
    return bObject;
  }

  public  void setBObject(B _bObject) {
    bObject = _bObject;
  }
}

@Entity
@Table(name = "B")
public class B implements Serializable {

  private Long id;

  private Long aId;

  @Id
  public Long getId() {
    return id;
  }

  public void setId(Long _id) {
    id = _id;
  }

@Column(name="a_id")
  public Long getAId() {
    return id;
  }

  public void setAId(Long _aId) {
    aId = _aId;
  }
}


in the session bean I am getting List<A> as follows:

Code:
...
Query query = em.createQuery("select a from A a left outer join a.bObject as b ");
    query.setFirstResult(start);
    query.setMaxResults(MSG_PER_PAGE);
    List<A> result =query.getResultList();
...


The problem is that every time when there is no record in table B that corresponds to record in table A I am getting the javax.persistence.EntityNotFoundException: Unable to find B with id 123.

I also notice that if record in table B exists then I am getting just one join query in the log
Code:
select A0_.id as id10_0_, B1.id as id_11_1_ from  A A0_ left outer join B B1_ on A0_.id=B_.a_id


otherwise I am getting join query + additional select from table B.
Code:
select A0_.id as id10_0_, B1.id as id_11_1_ from  A A0_ left outer join B B1_ on A0_.id=B_.a_id

select  B0_.id as id11_0_, B0_.a_id as a_id2_11_0_ from B B0_
where B0_.a_id=?


I am running Jboss 4.0.4.
Any help is appreciated.

Thanks,
Ed[/code]


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.