generate « Fetch « JPA Q&A

1. JPA join fetch association table with N select generated by Hibernate?

I am using JPA with Hibernate3 as the implementation. I have an association table UsrGrp
@Basic(optional = false)
@Column(name = "usr_id")
private String usrId;
@OneToMany(mappedBy = "usr")
private List<UsrGrp> usrGrpList;
protected UsrGrpPK usrGrpPK;
@Column(name = "updated_by")
private String updatedBy;
@Column(name ...

2. JPA Hibernate left join fetch generating mutiple queries

I have a jpql query to eagerly fetch multi level associations as follows

  select distinct s from Singer s
  left join fetch s.singerIdentifiers si  //singerIdentifiers is collection in ...

3. Help : Need to retrieve SQL Query from Criteria or HQL (SQL which is generated by Hibernate)

I want to retrieve or access the hibernate generated SQL query in Java Code and need to pass it some where else. (Mostly I want to use it for the purpose of Reporting where if this is possible It will save lot of time in writting the complex SQL queries) Is it possible some how ? Thanks in advance.

4. How to retrieve values generated by auto_increment in mysql

Hi, is there a way/a switch to tell hibernate to populate new objects with the keys generated with the auto_increment? e.g. using Statement.RETURN_GENERATED_KEYS with the insert?! I get all sorts of problems when inserting multiple objects (NonUniqueObjectException), because all objects have the same primary key (0) - I suppose it's just a switch that I'm missing?! cheers stefan

5. How to retrieve id generated by trigger in DB

Hibernate version: 3.2 I am generating the id with a trigger in the DB, that is itself calling a sequence. But I cannot retrieve the generated id for future use in the application. Something like this: myObjectToPersist = new ObjectToPersist(); myObjectToPersist.setId(Long.valueOf("-1")); ... Then, when I want to persist just call: saveOrUpdate(myObjectToPersist) After this is executed, on the DB itself the new ...

6. Retrieve generated SQL

Hibernate version: 3.2.4 I am looking for the SQL that is generated similarily in hibernate.show_sql. We need the sql and the parameters because we want to forward it to another database. I am well aware of the replication option available in MySQL, but that causes another problem that I don't want to get into. I have noticed that Interceptor will solve ...