I have JPA entity (Object A) with a One-Many owning relationship (Object B) in an ArrayList.
I want to be able to query (either Hibernate or JPA) for Object A without having any of the instances of association Object B returned (no proxies or otherwise) in the One-Many ArrayList.
Ideally the returned ArrayList would be null or empty.
...
Was thinking about a scenario, suppose two entities, Customer and Order. Suppose I want to see all distinct customers who fulfills a certain criteria, who has one or more orders fulfilling a criteria.
If I use something like:
Select distinct cust from Customer cust join cust.orders order where order.x = 'y' and cust.z = 1
The above ...
I have two entities:
@Entity
public class Customer implements java.io.Serializable {
...
@OneToMany(fetch=FetchType.EAGER, mappedBy="customer")
private Set<CustomerOrder> customerOrders;
...
@Entity
public class CustomerOrder implements java.io.Serializable {
....
private double cost;
@ManyToOne
@JoinCo...
The following simple code throws exception:
entityManager.createQuery("SELECT c FROM Customer c");
But if I write
entityManager.createNativeQuery("SELECT c.* FROM Customer c", Customer.class)
then it works without any error. What might be wrong? I use GlassFish v2.1 with Toplink-essentials.
...
I was trying to do something that apparently doesn't work in JPQL:
JPQL:
select c from Car c
left join fetch c.owner
where c.type in (?1)
order by c.model
Code:
public List<Car> findCarsFilterByTypes(CarType[] types) {
return (List<Car>) this.entityManager.createNamedQuery("dealership.findCarsFilterByType...
I have a JPA object which has a many-to-many relationship like this:
@Entity
public class Role {
//...
@ManyToMany(fetch=FetchType.EAGER)
@JoinTable(
name="RolePrivilege",
joinColumns=
@JoinColumn(name="role", referencedColumnName="ID"),
inverseJoinColumns=
@JoinColumn(name="privilege", referencedColumnName="...
I have the following field definitions in one of my JPA entities:
@Column(nullable = false, name = "start_time",
columnDefinition= "TIMESTAMP WITH TIME ZONE")
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
private Date startTime = new Date();
@Column(nullable = true, name = "end_time",
columnDefinition= "TIMESTAMP WITH TIME ZONE")...
The code schematic below works fine but it breaks our coding guidelines due to the unchecked cast. How can this be re-written to use createQuery or otherwise avoid the unchecked cast?
Note 1: using hibernate
Note 2: @SuppressWarnings("unchecked") is not the answer
@Entity @Table(name="Foo") class Foo {
@EmbeddedId FooPK pk;
...
...
I'm using oracle10g database and eclipselink, I need to obtain the last inserted key from the table so i've created this query
javax.persistence.Query q =
em.createQuery("SELECT nvl(MAX(c.myAtt),0) " +
"from myTable as c");
return Integer.parseInt(q.getSingleResult().toS...
Hi,
I am trying to write a JPQL query with a like clause:
...LIKE '%:code%'
I would like to have code=4 and find
455
554
646
...
I cannot pass :code = '%value%'
namedQuery.setParameter("%" + this.value + "%");
because in another place I need :value not wrapped by the % chars. Any help?
Thank you
...
Hello everybody,
I need to compare two dates in a JPQL query but it doesn't work.
Here is my query:
Query query = em.createQuery("SELECT h FROM PositionHistoric h, SeoDate d WHERE h.primaryKey.siteDb = :site AND h.primaryKey.engineDb = :engine AND h.primaryKey.keywordDb = :keyword AND h.date = d AND d.date <= :date ORDER BY h.date DES...
JPA 1.0 specification is not defining the Criteria API which provides a programmatic approach for creating and modifying JPA Queries. Is there any API for building SQL and JPQL Queries like the way Hibernate Criteria Api is doing?
...
Hi all,
I hava 2 objects associate by oneToMany relationship("One Model can have many events").
I'm trying to make a subquery in ejbql to find models for one event, like this:
SELECT model
FROM RegModelValue model
WHERE :event IN (model.events)
....
but toplink doent recognize model alias and tell me "Internal Exception: line 1:12...
Simple JPA/JPQL question. I have an entity with a ManyToMany relationship:
@Entity
public class Employee {
@ManyToMany
@JoinTablename="employee_project"
joinColumns={@JoinColumn(name="employee_id"}
inverseJoinColumns={@JoinColumn(name="project_id"})
private List<Project> projects;
What is the JPQL query to retu...
Is it possible to run a "MEMBER OF" query against associative arrays? If so, what does the syntax look like? The obvious workaround is a native query but that gets pretty messy what with all the joins and such. I'd like to test for existence of an object within the map's key set, value collection or entry set. Maybe something like th...
Whenever I try to set a list as a parameter for use in an IN expression I get an Illegal argument exception. Various posts on the internet seem to indicate that this is possible, but it's certainly not working for me. I'm using Glassfish V2.1 with Toplink.
Has anyone else been able to get this to work, if so how?
here's some example ...
Hi.
I have a pretty simple sql I need to perform.
I have a ProcessUser, Role and a ProcessUserRole table. A straight forward many-to-many
I want to select all ProcessUser's that does also have a Role of admin.
However my jpa sql fails because my user also has role officer, so it is retrieved in the list.
Here is the sql:
entityMana...
Is there any sort of tool available which allows one to execute JPQL queries against a database "directly"? I would like to type JPQL queries directly into a window and execute them.
Of course it would probably require me to do quite a bit of configuration so that it would be aware of my JPA entities, etc., but I guess it could be done...
I'm having an issue with a SELECT NEW query.
Query q = em.createQuery(
"SELECT NEW com.bcbst.odstats.ejb.RangeStats(a.folderName, SUM(a.hits)) " +
"FROM ODStat a GROUP BY a.folderName");
return q.getResultList();
I get the following stacktrace when I try to run this query. RangeStats does have public methods, ...
Hi,
with native SQL I get the database time with a statement like:
SELECT CURRENT_TIMESTAMP
with JPQL I get the same result with:
SELECT CURRENT_TIMESTAMP
FROM Customer c
WHERE c.id=1
Is there a way to get rid of the last two lines?
thanks,
...