[hibernate-dev] Doubts in using Hibernate with createQuery with JPA annotations
Paulo Ribeiro
paribe at gmail.com
Thu Dec 18 15:43:12 EST 2008
Hello,
I'm using JPA with Hibernate 3.2.6 JPA and a party with some queries I
use Hibernate
I wanted to take a createQuery doubts about because I have an object
I'm using JPA Annotation in the two objects ....
One is a Public Private (1-1)
When I try to bring in a select object of my mistake
doing join between these objects .....
-------------------------
try{
Session session = (Session) get.getManager().getDelegate();
List listas = session.createQuery("select pri from Public as pub
join pub.Private as pri where pub.id=4")
.list();
System.out.println("Size listas = "+listas.size());
} catch(Exception e){
System.out.println("Erro ="+e);
}
-- da o erro
Erro testCreateQuery() =org.hibernate.QueryException: could not
resolve property: Private of: br.com.Public [select pri from
br.com.Public as pub join pub.Private as pri where pub.id=4]
------------------------------------
and so when I do not give me error
My question is I have Proquar query with 5 objects (tables) that I
will have to show the scope of each
object. Example: select a.codigo, b.nome, c.saldo, d.saldoanterior
from the object, object, b, c object, object d
How well do ?????? since when do I join between the objects of error ??????????
With the above situation it worked because it is (1-1) and when you
have (1-N) of various objects ....
If anyone can help me would ...
Tks
---------------------
List listas = session.createQuery("select pri from Private as pri
where pri.id=4")
.list();
System.out.println("Size listas = "+listas.size());
-- resultado
Size listas = 1
-----------------------------------
import java.security.PublicKey;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
@Entity
@Table(name="PUBLIC")
public class Public extends AbstractImsPublicKey {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "PUBLICKEY_ID")
private long id;
@Column
private int keySize;
@Column
private Date generationDate;
@Column
private String base64EncodedPublicKey;
private transient PublicKey publicKey;
@OneToOne(mappedBy = "publicKey")
private ImsDigitalCertificateImpl cert;
public Date getGenerationDate() {
return generationDate;
}
public int getHandle() {
// TODO Auto-generated method stub
return 0;
}
public PublicKey getPublicKey() {
return publicKey;
}
public void setGenerationDate(Date date) {
this.generationDate = date;
}
public void setHandle(int handle) {
// TODO Auto-generated method stub
}
public void setPublicKey(PublicKey publicKey) {
this.publicKey = publicKey;
}
public Long getId() {
return id;
}
public String getBase64EncodedPublicKey() {
return base64EncodedPublicKey;
}
public int getKeySize() {
return keySize;
}
public void setBase64EncodedPublicKey(String key) {
this.base64EncodedPublicKey = key;
}
public void setKeySize(int size) {
this.keySize = size;
}
public ImsDigitalCertificateImpl getCert() {
return cert;
}
public void setCert(ImsDigitalCertificateImpl cert) {
this.cert = cert;
}
public void setId(long id) {
this.id = id;
}
}
-----
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
@Entity
@Table(name="PRIVATE")
public class Private extends AbstractProtectedPrivateKey {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "PRIVATEKEY_ID")
private long id;
@Column
private String base64EncodedPrivateKey;
@OneToOne
@JoinColumn(name = "PUBLICKEY_ID")
private ImsPublicKeyImpl publicKey;
public String getBase64EncodedPrivateKey() {
return base64EncodedPrivateKey;
}
public void setBase64EncodedPrivateKey(String raw) {
this.base64EncodedPrivateKey = raw;
}
public Long getId() {
return id;
}
public ImsPublicKeyImpl getPublicKey() {
return publicKey;
}
public void setPublicKey(ImsPublicKeyImpl publicKey) {
this.publicKey = publicKey;
}
public void setId(long id) {
this.id = id;
}
}
More information about the hibernate-dev
mailing list