cancel
Showing results for 
Search instead for 
Did you mean: 

SAP JPA simple query

Former Member
0 Kudos

Hello, experts!

I have a simple entity

@Entity
@Table( schema = "dbo", name = "class")
public class ClassEntity {
 
  private Long id;
        @Id
	@Column(name="id")
	@GeneratedValue(strategy= GenerationType.IDENTITY)
    public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
}

I have about 10.000 records in this table. The simplest query "SELECT c FROM ClassEntity c WHERE c.id=:id" tooks 3-4 seconds! I have found (using mssql profiler) that SAP JPA implementation selects ALL records and only then returns the one I need!

Moreover, query "SELECT count(c) FROM ClassEntity c" tooks 3-4 seconds too, and its behaviour is the same! Have anyone an idea, whats going on? How can I select just 1 record (ClassEntity) from the table?

Thanks for any advice.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Andrey,

I think you must use the EntityManager interface in order to find an entity by its primary key.

Former Member
0 Kudos

Hello, Sergi.

Yes, you are right, but em.find() can't solve the problem with count() and searching by non-id fields.

I have found, that if underlying db is Oracle, this problem disappears.

adrian_goerler
Active Participant
0 Kudos

Hi Andrey,

on which DB have you observed the issue you were describing initially?

-Adrian

adrian_goerler
Active Participant
0 Kudos

Hi Andrey,

the behavior you are describing would be absolutely unexpected.

Could you please double check using the SQL Trace (http://<host>:<port>/OpenSQLMonitors) that the generated SQL is a you are describing it.

-Adrian