sql « Join « JPA Q&A





1. Hibernate HQL: Converting a SQL Statement to HQL (with subselects/joins)    stackoverflow.com

i would very much appreciate your help in transforming the following SQL statement to a valid HQL Statement. I tried for hours but was not successfull:

SELECT * FROM master as ...

2. Hibernate HQL to basic SQL (no joins)    stackoverflow.com

I working on a project with Hibernate and we need to replace Hibernate with some "home made persistence" stuff. The idea is that the project is big enough, and we have many ...

3. Hibernate Criteria Left Joining Two Tables    stackoverflow.com

I have two entities, say Business and Area. Relevant properties:
Business - area, area2, code
Area - areaId, areaName area and area2 of Business map to the id in Area I'm trying to write a Hibernate ...

4. Hibernate set forcing inner join causing duplicate records    stackoverflow.com

I have an Order class that contains a HashSet of OrderLineItem which is mapped as such in Hibernate:

<set name="orderLineItems" table="order_line_items" inverse="true" lazy="false" fetch="select" cascade="save-update">
    <key>
    ...

5. Multiple JOIN (SQL)    stackoverflow.com

My problem is Play! Framework / JPA specific. But I think it's applicable to general SQL syntax. Here is a sample query with a simple JOIN:

return Post.find(
    "select distinct ...

6. SQL to HQL help    stackoverflow.com

I've got a fairly complicated SQL query that I wrote in native SQL/MySQL syntax that I want to rewrite in HQL to be db-agnostic, but am running into some serious problems. ...

7. Join two tables with Play Framework and JPA    stackoverflow.com

How can I join two tables by using java play framework and jpa, I really have a hardtime converting my MySQL query to jpa query. Here is the MySQL query that I ...

8. SQL to HQL (Having issue in Left Outer Join)    coderanch.com

Is there any direct relationship between A and B? Is it expressed in Java, not just in DB? As far as I know, HQL likes property based joins, like Entity A has a field "private B b" and the join is select * from A as a left outer join a.b as B ....

9. SQL Outer Join    forum.hibernate.org

I'm trying to reproduce the results of a single SQL call in Hibernate - but so far no luck. The SQL query is: Code: SELECT BN.*, OP.*, MA.*, DOC.* FROM BOM_NODE BN LEFT OUTER JOIN MATERIAL MA ON BN.DOCUMENT_ID = MA.ID AND BN.DOCUMENT_TYPE = 'M' LEFT OUTER JOIN OPERATION OP ON BN.DOCUMENT_ID = OP.ID AND BN.DOCUMENT_TYPE = 'O' ...





10. [HQL] SQL translation adding multiple joins    forum.hibernate.org

(I'm french so fields in my DB are in french... but to help you understanding the sample, an Agriculteur is a Farmer, the EtatAgriculteur is the State of the farmer (from a professional point of view -does he grow cows, does he cultivate cereals, etc...) and the Parcelle are Field (to cultivate cereals, to grow cows...)

11. sql join...Can someone show an example..    forum.hibernate.org

Still trying to get a handle on the joining. I would like to eventually use left and right joins but for now trying this query below and comparing it with one where I use paths day.meetingDays.meeting.schedule.scheduleId=1. This is my join query: (The examples in the documentation do not cover this case) Query q = session.createQuery("select day " + " from Day ...

12. Using custom SQL in joined subtypes    forum.hibernate.org

Here's a little stumper for the Hibernate team. I posted this in another thread, but I think it got lost, so I'm re-posting it as its own topic. How can I query joined subtypes using custom SQL (the createSQLQuery() method)? That is, suppose I have the query: Code: SELECT {subtype.*} FROM SUBTYPE {subtype} ...

13. Best Practices for Multiple SQL Joins    forum.hibernate.org

14. SQL Error - "Left outer join" construct appearing    forum.hibernate.org

Query is as shown below. Because of words "Left outer join", query gives error "SQL command not ended properly". Hibernate version: 2.2 select formdatade0_.id as id1_, formdatade0_.CREATED_ON as CREATED_ON1_, formdatade0_.CREATED_BY as CREATED_BY1_, formdatade0_.PROPERTY_NAME as PROPERTY4_1_, formdatade0_.QUESTION as QUESTION1_, formdatade0_.ANSWER_TYPE as ANSWER_T6_1_, formdatade0_.QUESTION_NUMBER as QUESTION7_1_, formdatade0_.ANSWER_NUMBER as ANSWER_N8_1_, formdatade0_.SPECIAL_TREATMENT as SPECIAL_9_1_, formdatade0_.PAGE_NO as PAGE_NO1_, formdatade0_.LINE_NO as LINE_NO1_, formdatade0_.MAX_LENGTH as MAX_LENGTH1_, formdatade0_.LINE_BREAK as ...

15. Hibernate2 + SQL + inner join    forum.hibernate.org

sql = ""; sql += "SELECT {ac}.ACTI_CODIGO_ACTIVIDAD AS {ac.codigoAC} "; sql += "FROM ACTIVIDADES {ac} "; sql += "inner join ACTIVIDADES_LINEA {li} ON {li}.ACLI_CODIGO_ACTIVIDAD = {ac}.ACTI_CODIGO_ACTIVIDAD "; sql += "WHERE {li}.ACLI_CODIGO_LINEA = 'CC'"; Query storeQuery = sess.createSQLQuery(sql, new String[] {"ac","li"}, new Class[] { Actividad.class, ActividadLinea.class} ); ...

16. left outer join: sql command not properly ended Error    forum.hibernate.org

Mapping documents: ...





17. Criteria API to build SQL with inner joins, when HSQL works    forum.hibernate.org

Mapping documents: Resurs (resource) Code: ....

18. Using Native SQL with Join .Getting null pointer exception    forum.hibernate.org

Thank you very much for ur quick response. In fact your statment opened my eyes. In fact my example query with join , resultset contained Nulls in the joined table Then I again executed another query with join , resultset containing both null and non null in the joined table. I gave SOP for the non null rows which it printed. ...

19. Criteria: SQL fetches data from all the tables in the joins    forum.hibernate.org

Hi All, I am using Criteria API to fetch a domain object based on some conditions. But the SQL query fired by Hibernate contains all the columns from all the tables it is doing the join on. Sql Query being fired: Code: SELECT this_.teacher_id AS person1_1_5_, this_1_.first_name AS first2_1_5_, this_1_.middle_name AS middle3_1_5_, this_1_.last_name AS last4_1_5_, ...

20. hibernate join, can't convert sql to hql    forum.hibernate.org

hi. im using mysql db. i have to tables in database : employees and registration. in registration table are written employees registered working hours(registering by projects tasks). hours are registered every day. i need to make query which returns a list of all employees and their registered hours during some period. if employee didnt registered hours during that period, query should ...

21. Invalid SQL from trying to join tables    forum.hibernate.org

I'm trying to use Hibernate to access a database that includes a unique many-to-many relationship between two entities with a couple of extra fields. My first attempt is to use a set in one of the entity objects and component as the member-type of that set. I can query both entity tables without any trouble, but when I try to join ...

22. About using LEFT JOIN with native SQL    forum.hibernate.org

Hi, I have a native SQL like this: select m.*, a.* from message left join attachment on m.id = a.id when this SQL is executed in the DB, the following will be returned: m.id | a.id ------------ 1 1 2 2 3 4 5 3 I executed the SQL query as follow: Session sess = sessionFactory.openSession(); SQLQuery query = sess.createSQLQuery(sql.toString()).addEntity("m", Message.class) ...

23. SQL LEFT JOIN in Hibernate    forum.hibernate.org

24. SQL to HQL (Having issue in Left Outer Join)    forum.hibernate.org

hi, I think I'm doing the same as what's suggested here. Filter enabled on a one-to-many collection myCollectionField of ObjectA, then outer join. Then I did With Criterion API: session.createCriteria(ObjectA.class) .createAlias("myCollectionField", "collB", CriteriaSpecification.LEFT_JOIN) .add(Restrictions.in("id", myIds)) .setFetchMode("collB" , FetchMode.JOIN) .list(); Then I tried with HQL: session.createQuery("select objA, collB from ObjectA objA" + " left outer join objA.myCollectionField collB where objA.id in (:idList)") ...