File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA - Entity Manager Query

 
rex hindlekar
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic