wood burning stoves
The moose likes Object Relational Mapping and the fly likes JPA - Entity Manager Query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA - Entity Manager Query" Watch "JPA - Entity Manager Query" New topic
Author

JPA - Entity Manager Query

rex hindlekar
Greenhorn

Joined: Feb 25, 2010
Posts: 16
<code>

import java.io.Serializable;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

@MappedSuperclass
public class SuperObject implements Serializable {

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

public Long getIdone() {
return idone;
}
public void setIdone(Long idone) {
this.idone = idone;
}
}

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

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToMany;

@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public class Bank extends SuperObject {

@Column(nullable=false)

private String firstName;
private String lastName;


@OneToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL, mappedBy="bank")


public String getFirstName() {
return firstName;
}
public void setFirstName(final String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(final String lastName) {
this.lastName = lastName;
}


}




import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="transaction_type", discriminatorType=DiscriminatorType.STRING)
public abstract class BankTransaction extends SuperObject {


@ManyToOne(fetch=FetchType.LAZY, cascade=CascadeType.PERSIST, optional=false)
private Bank bank;



public Bank getBank () {
return bank;
}
public void setBank (Bank bank) {
this.bank = bank;
}

}

</code>

I need help in writing the createQuery where I need to access the id that is there in the SuperObject in the where statement.

em.createQuery("from BankTransaction bt where bt.idone >=:idone")

This gives error while casting to the Long value.

Can anyone help me?
Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42958
    
  73
Please edit your post to UseCodeTags. It's unnecessarily hard to read the code as it is, making it less likely that people will bother to do so.
 
Have you checked out Aspose?
 
subject: JPA - Entity Manager Query
 
It's not a secret anymore!