-->
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: Hibernate Criteria inner join get full entity class field
PostPosted: Thu Aug 25, 2011 2:17 am 
Newbie

Joined: Wed Aug 24, 2011 10:57 am
Posts: 2
Hello guys again,
I have two model Entitiy class.their name is A and B.

@Entity
public class A implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

@Column(name = "NameA")
private String nameA;

public B getBid() {
return b;
}

public void setBid(B bid) {
this.b = bid;
}

public String getNameA() {
return nameA;
}

public void setNameA(String nameA) {
this.nameA = nameA;
}

@JoinColumn(name = "BID", referencedColumnName = "ID")
@ManyToOne(fetch= FetchType.LAZY)
private B b;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}
}


-------------------------------------------------------------


@Entity
public class B implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

@Column(name = "NameB")
private String nameB;


public String getNameB() {
return nameB;
}

public void setNameB(String nameB) {
this.nameB = nameB;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}
}



-------------------------------------------------------------


And Here is my problem

My Criteria Query

Criteria criteria =session.createCriteria(A.class);
criteria.createCriteria("b");
criteria.setProjection(Projections.property("b"));
List lst =criteria.list();


---------> Sql Query Result
select
this_.BID as y0_
from
A this_
inner join
B b1_
on this_.BID=b1_.id


Yeah,When we are this point,I want to full field of B class in SQL Query result but ı have to use Criteria API

The Query Result is Like this

select
b1_.id as id1_,
b1_.NameB as NameB1_
A a0_
inner join
B b1_
on a0_.BID=b1_.id


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.