Performance issue with Criteria API - java

I am doing a dynamic query using Criteria API, the problem I have is that when this query is executed, each query is repeated for each of the records returned by the query (this is shown by the Hibernate console). Then I get very high response times.
My specification class is as follows:
public class PacienteSpecification implements Specification<Paciente> {
private Paciente filter;
public PacienteSpecification(Paciente filter) {
super();
this.filter = filter;
}
public Predicate toPredicate(Root<Paciente> root, CriteriaQuery<?> cq,
CriteriaBuilder cb) {
Predicate p = cb.conjunction();
p.getExpressions().add(cb.equal(root.get("eliminado"), "N"));
if (filter.getNombres() != "") {
p.getExpressions().add(cb.like(cb.upper(root.get("nombres")), "%" + filter.getNombres().toUpperCase() + "%"));
}
if(filter.getApePaterno() != "") {
p.getExpressions().add(cb.or(cb.like(cb.upper(root.get("apePaterno")), "%" + filter.getApePaterno().toUpperCase() + "%")));
}
if(filter.getApeMaterno() != "") {
p.getExpressions().add(cb.or(cb.like(cb.upper(root.get("apeMaterno")), "%" + filter.getApeMaterno().toUpperCase() + "%")));
}
if (filter.getFicha() != "") {
p.getExpressions().add(cb.equal(cb.upper(root.get("ficha")), filter.getFicha()));
}
if(filter.getFechaNacimiento() != null){
p.getExpressions().add(cb.equal(root.get("fechaNacimiento"), filter.getFechaNacimiento()));
}
if(filter.getGenero() != null){
p.getExpressions().add(cb.equal(root.get("genero"), filter.getGenero()));
}
return p;
}
}
My service that calls the repository is as follows:
List<Paciente> listaPacientes = new ArrayList<Paciente>();
Specification<PacienteDoc> pacienteDocEspecificacion = new PacienteDocEspecification(pacBusqueda.getPacienteDocs().get(0));
final List<PacienteDoc> pacDoc = pacienteDocRep.findAll(pacienteDocEspecificacion);
and when making the service call the hibernate console shows me a query for each record:
Hibernate: select pacientedo0_.id_paciente_doc as id_paciente_doc1_44_, pacientedo0_.eliminado as eliminado2_44_, pacientedo0_.fecha_creacion as fecha_creacion3_44_, pacientedo0_.fecha_ult_modificacion as fecha_ult_modifica4_44_, pacientedo0_.id_usuario_creacion as id_usuario_creacio5_44_, pacientedo0_.id_usuario_ult_mod as id_usuario_ult_mod6_44_, pacientedo0_.num_documento as num_documento7_44_, pacientedo0_.id_paciente as id_paciente8_44_, pacientedo0_.id_tipo_documento as id_tipo_documento9_44_ from dgs_core.paciente_doc pacientedo0_ where 1=1
Hibernate: select paciente0_.id_paciente as id_paciente1_43_0_, paciente0_.ape_materno as ape_materno2_43_0_, paciente0_.ape_paterno as ape_paterno3_43_0_, paciente0_.celular as celular4_43_0_, paciente0_.id_comuna as id_comuna19_43_0_, paciente0_.direccion as direccion5_43_0_, paciente0_.eliminado as eliminado6_43_0_, paciente0_.email as email7_43_0_, paciente0_.id_estado_civil as id_estado_civil20_43_0_, paciente0_.id_etnia as id_etnia21_43_0_, paciente0_.fecha_creacion as fecha_creacion8_43_0_, paciente0_.fecha_defuncion as fecha_defuncion9_43_0_, paciente0_.fecha_nacimiento as fecha_nacimiento10_43_0_, paciente0_.fecha_ult_modificacion as fecha_ult_modific11_43_0_, paciente0_.ficha as ficha12_43_0_, paciente0_.fono as fono13_43_0_, paciente0_.fono_emergencia as fono_emergencia14_43_0_, paciente0_.id_genero as id_genero22_43_0_, paciente0_.id_unidad_creacion as id_unidad_creacio15_43_0_, paciente0_.id_usuario_creacion as id_usuario_creaci16_43_0_, paciente0_.id_usuario_ult_mod as id_usuario_ult_mo17_43_0_, paciente0_.id_nacionalidad as id_nacionalidad23_43_0_, paciente0_.nombres as nombres18_43_0_, paciente0_.id_prevision as id_prevision24_43_0_, paciente0_.id_profesion as id_profesion25_43_0_, catalogo1_.id_catalogo as id_catalogo1_35_1_, catalogo1_.activo as activo2_35_1_, catalogo1_.comentario as comentario3_35_1_, catalogo1_.id_def_catalogo as id_def_catalogo14_35_1_, catalogo1_.orden as orden4_35_1_, catalogo1_.valido_desde as valido_desde5_35_1_, catalogo1_.valido_hasta as valido_hasta6_35_1_, catalogo1_.valor1 as valor7_35_1_, catalogo1_.valor2 as valor8_35_1_, catalogo1_.valor3 as valor9_35_1_, catalogo1_.valor4 as valor10_35_1_, catalogo1_.valor5 as valor11_35_1_, catalogo1_.valor6 as valor12_35_1_, catalogo1_.version as version13_35_1_, definicion2_.id_def_catalogo as id_def_catalogo1_36_2_, definicion2_.activo as activo2_36_2_, definicion2_.columna1 as columna3_36_2_, definicion2_.columna2 as columna4_36_2_, definicion2_.columna3 as columna5_36_2_, definicion2_.columna4 as columna6_36_2_, definicion2_.columna5 as columna7_36_2_, definicion2_.columna6 as columna8_36_2_, definicion2_.comentario as comentario9_36_2_, definicion2_.nombre_catalogo as nombre_catalogo10_36_2_, definicion2_.valido_desde as valido_desde11_36_2_, definicion2_.valido_hasta as valido_hasta12_36_2_, definicion2_.version as version13_36_2_, catalogo3_.id_catalogo as id_catalogo1_35_3_, catalogo3_.activo as activo2_35_3_, catalogo3_.comentario as comentario3_35_3_, catalogo3_.id_def_catalogo as id_def_catalogo14_35_3_, catalogo3_.orden as orden4_35_3_, catalogo3_.valido_desde as valido_desde5_35_3_, catalogo3_.valido_hasta as valido_hasta6_35_3_, catalogo3_.valor1 as valor7_35_3_, catalogo3_.valor2 as valor8_35_3_, catalogo3_.valor3 as valor9_35_3_, catalogo3_.valor4 as valor10_35_3_, catalogo3_.valor5 as valor11_35_3_, catalogo3_.valor6 as valor12_35_3_, catalogo3_.version as version13_35_3_, catalogo4_.id_catalogo as id_catalogo1_35_4_, catalogo4_.activo as activo2_35_4_, catalogo4_.comentario as comentario3_35_4_, catalogo4_.id_def_catalogo as id_def_catalogo14_35_4_, catalogo4_.orden as orden4_35_4_, catalogo4_.valido_desde as valido_desde5_35_4_, catalogo4_.valido_hasta as valido_hasta6_35_4_, catalogo4_.valor1 as valor7_35_4_, catalogo4_.valor2 as valor8_35_4_, catalogo4_.valor3 as valor9_35_4_, catalogo4_.valor4 as valor10_35_4_, catalogo4_.valor5 as valor11_35_4_, catalogo4_.valor6 as valor12_35_4_, catalogo4_.version as version13_35_4_, catalogo5_.id_catalogo as id_catalogo1_35_5_, catalogo5_.activo as activo2_35_5_, catalogo5_.comentario as comentario3_35_5_, catalogo5_.id_def_catalogo as id_def_catalogo14_35_5_, catalogo5_.orden as orden4_35_5_, catalogo5_.valido_desde as valido_desde5_35_5_, catalogo5_.valido_hasta as valido_hasta6_35_5_, catalogo5_.valor1 as valor7_35_5_, catalogo5_.valor2 as valor8_35_5_, catalogo5_.valor3 as valor9_35_5_, catalogo5_.valor4 as valor10_35_5_, catalogo5_.valor5 as valor11_35_5_, catalogo5_.valor6 as valor12_35_5_, catalogo5_.version as version13_35_5_, catalogo6_.id_catalogo as id_catalogo1_35_6_, catalogo6_.activo as activo2_35_6_, catalogo6_.comentario as comentario3_35_6_, catalogo6_.id_def_catalogo as id_def_catalogo14_35_6_, catalogo6_.orden as orden4_35_6_, catalogo6_.valido_desde as valido_desde5_35_6_, catalogo6_.valido_hasta as valido_hasta6_35_6_, catalogo6_.valor1 as valor7_35_6_, catalogo6_.valor2 as valor8_35_6_, catalogo6_.valor3 as valor9_35_6_, catalogo6_.valor4 as valor10_35_6_, catalogo6_.valor5 as valor11_35_6_, catalogo6_.valor6 as valor12_35_6_, catalogo6_.version as version13_35_6_, catalogo7_.id_catalogo as id_catalogo1_35_7_, catalogo7_.activo as activo2_35_7_, catalogo7_.comentario as comentario3_35_7_, catalogo7_.id_def_catalogo as id_def_catalogo14_35_7_, catalogo7_.orden as orden4_35_7_, catalogo7_.valido_desde as valido_desde5_35_7_, catalogo7_.valido_hasta as valido_hasta6_35_7_, catalogo7_.valor1 as valor7_35_7_, catalogo7_.valor2 as valor8_35_7_, catalogo7_.valor3 as valor9_35_7_, catalogo7_.valor4 as valor10_35_7_, catalogo7_.valor5 as valor11_35_7_, catalogo7_.valor6 as valor12_35_7_, catalogo7_.version as version13_35_7_, catalogo8_.id_catalogo as id_catalogo1_35_8_, catalogo8_.activo as activo2_35_8_, catalogo8_.comentario as comentario3_35_8_, catalogo8_.id_def_catalogo as id_def_catalogo14_35_8_, catalogo8_.orden as orden4_35_8_, catalogo8_.valido_desde as valido_desde5_35_8_, catalogo8_.valido_hasta as valido_hasta6_35_8_, catalogo8_.valor1 as valor7_35_8_, catalogo8_.valor2 as valor8_35_8_, catalogo8_.valor3 as valor9_35_8_, catalogo8_.valor4 as valor10_35_8_, catalogo8_.valor5 as valor11_35_8_, catalogo8_.valor6 as valor12_35_8_, catalogo8_.version as version13_35_8_ from dgs_core.paciente paciente0_ left outer join dgs_core.catalogo catalogo1_ on paciente0_.id_comuna=catalogo1_.id_catalogo left outer join dgs_core.definicion_catalogo definicion2_ on catalogo1_.id_def_catalogo=definicion2_.id_def_catalogo left outer join dgs_core.catalogo catalogo3_ on paciente0_.id_estado_civil=catalogo3_.id_catalogo left outer join dgs_core.catalogo catalogo4_ on paciente0_.id_etnia=catalogo4_.id_catalogo left outer join dgs_core.catalogo catalogo5_ on paciente0_.id_genero=catalogo5_.id_catalogo left outer join dgs_core.catalogo catalogo6_ on paciente0_.id_nacionalidad=catalogo6_.id_catalogo left outer join dgs_core.catalogo catalogo7_ on paciente0_.id_prevision=catalogo7_.id_catalogo left outer join dgs_core.catalogo catalogo8_ on paciente0_.id_profesion=catalogo8_.id_catalogo where paciente0_.id_paciente=?

It seems that Your entity mapping is more or less sth like this:
public class Paciente {
...
#OneToMany(fetch=FetchType.EAGER)
private Set<PacienteDoc> docs = new HashSet<>();
...
}
And then You run into What is the "N+1 selects problem" in ORM (Object-Relational Mapping)?
To fix that simply change #OneToMany(fetch=FetchType.EAGER) to #OneToMany which is equal to #OneToMany(fetch=FetchType.LAZY)

Related

How to prevent Hibernate to load collection with back reference when I need only count()

The goal is to count collection elements without initializing collection. I made it work in some way, but it's not the soulution that I'd say I want.
Back reference is needed because each Price gets some data from Article while being indexed by Hibernate Search.
Join column gives me an option to have only two tables, avoiding 3rd linking table.
#Entity #Indexed
class Article {
String name;
#JsonManagedReference
#OneToMany
#LazyCollection(org.hibernate.annotations.LazyCollectionOption.EXTRA)
#JoinColumn(name = "article_id")
#Field(...bridge = #FieldBridge(impl = PriceBridge.class))
Set<Price> prices;
private User created;
private User updated;
}
#Entity #Indexed
class Price {
#Reference #JsonBackReference
#ManyToOne(fetch=FetchType.LAZY)
#Field(...bridge = #FieldBridge(impl = PriceArticleBridge.class))
private Article article;
#ManyToOne private Provider provider;
#ManyToOne private CustomCurrency currency;
private BigDecimal amount;
private User created;
private User updated;
}
This setup gives me 2 tables where Price table has article_id and there is no 3rd table for linking purposes. But while loading Article and issuing prices.size(), the whole collection is fetched. This is not good because many other entities are loaded too: Provider from Price and User many times because Provider also has its own 2 properties of User to track creator and updater.
When there is no #JoinColumn, 3rd linking table is created and then it starts to use COUNT() instead of loading the whole collection.
My only question is:
How can I keep only 2 tables and use .size() without loading the whole collection?
SQL example when not having #JoinColumn:
select count(prices_id) from article_prices where article_id =?
SQL example when having #JoinColumn (11 tables joined):
SELECT
prices0_.article_id AS article14_18_0_,
prices0_.id AS id1_18_0_,
prices0_.id AS id1_18_1_,
prices0_.date_created AS date_cre2_18_1_,
prices0_.date_last_update AS date_las3_18_1_,
prices0_.created_by_id AS created12_18_1_,
prices0_.last_update_by_id AS last_up13_18_1_,
prices0_.amount AS amount4_18_1_,
prices0_.article_id AS article14_18_1_,
prices0_.availability AS availabi5_18_1_,
prices0_.currency_id AS currenc15_18_1_,
prices0_.description AS descript6_18_1_,
prices0_.local_date_time_valid_from AS local_da7_18_1_,
prices0_.local_date_time_valid_to AS local_da8_18_1_,
prices0_.price_url AS price_ur9_18_1_,
prices0_.provider_id AS provide16_18_1_,
prices0_.purchase_url AS purchas10_18_1_,
prices0_.zone_id_valid_from_to AS zone_id11_18_1_,
user1_.id AS id1_27_2_,
user1_.date_created AS date_cre2_27_2_,
user1_.date_last_update AS date_las3_27_2_,
user1_.created_by_id AS created13_27_2_,
user1_.last_update_by_id AS last_up14_27_2_,
user1_.display_name AS display_4_27_2_,
user1_.failed_login_attempts AS failed_l5_27_2_,
user1_.full_name AS full_nam6_27_2_,
user1_.note AS note7_27_2_,
user1_.object_status AS object_s8_27_2_,
user1_.password AS password9_27_2_,
user1_.phone AS phone10_27_2_,
user1_.time_zone_id AS time_zo11_27_2_,
user1_.username AS usernam12_27_2_,
user2_.id AS id1_27_3_,
user2_.date_created AS date_cre2_27_3_,
user2_.date_last_update AS date_las3_27_3_,
user2_.created_by_id AS created13_27_3_,
user2_.last_update_by_id AS last_up14_27_3_,
user2_.display_name AS display_4_27_3_,
user2_.failed_login_attempts AS failed_l5_27_3_,
user2_.full_name AS full_nam6_27_3_,
user2_.note AS note7_27_3_,
user2_.object_status AS object_s8_27_3_,
user2_.password AS password9_27_3_,
user2_.phone AS phone10_27_3_,
user2_.time_zone_id AS time_zo11_27_3_,
user2_.username AS usernam12_27_3_,
user3_.id AS id1_27_4_,
user3_.date_created AS date_cre2_27_4_,
user3_.date_last_update AS date_las3_27_4_,
user3_.created_by_id AS created13_27_4_,
user3_.last_update_by_id AS last_up14_27_4_,
user3_.display_name AS display_4_27_4_,
user3_.failed_login_attempts AS failed_l5_27_4_,
user3_.full_name AS full_nam6_27_4_,
user3_.note AS note7_27_4_,
user3_.object_status AS object_s8_27_4_,
user3_.password AS password9_27_4_,
user3_.phone AS phone10_27_4_,
user3_.time_zone_id AS time_zo11_27_4_,
user3_.username AS usernam12_27_4_,
user4_.id AS id1_27_5_,
user4_.date_created AS date_cre2_27_5_,
user4_.date_last_update AS date_las3_27_5_,
user4_.created_by_id AS created13_27_5_,
user4_.last_update_by_id AS last_up14_27_5_,
user4_.display_name AS display_4_27_5_,
user4_.failed_login_attempts AS failed_l5_27_5_,
user4_.full_name AS full_nam6_27_5_,
user4_.note AS note7_27_5_,
user4_.object_status AS object_s8_27_5_,
user4_.password AS password9_27_5_,
user4_.phone AS phone10_27_5_,
user4_.time_zone_id AS time_zo11_27_5_,
user4_.username AS usernam12_27_5_,
customcurr5_.id AS id1_9_6_,
customcurr5_.date_created AS date_cre2_9_6_,
customcurr5_.date_last_update AS date_las3_9_6_,
customcurr5_.created_by_id AS created10_9_6_,
customcurr5_.last_update_by_id AS last_up11_9_6_,
customcurr5_.is_default AS is_defau4_9_6_,
customcurr5_.is_reference AS is_refer5_9_6_,
customcurr5_.java_currency AS java_cur6_9_6_,
customcurr5_.object_status AS object_s7_9_6_,
customcurr5_.sign_position AS sign_pos8_9_6_,
customcurr5_.val AS val9_9_6_,
user6_.id AS id1_27_7_,
user6_.date_created AS date_cre2_27_7_,
user6_.date_last_update AS date_las3_27_7_,
user6_.created_by_id AS created13_27_7_,
user6_.last_update_by_id AS last_up14_27_7_,
user6_.display_name AS display_4_27_7_,
user6_.failed_login_attempts AS failed_l5_27_7_,
user6_.full_name AS full_nam6_27_7_,
user6_.note AS note7_27_7_,
user6_.object_status AS object_s8_27_7_,
user6_.password AS password9_27_7_,
user6_.phone AS phone10_27_7_,
user6_.time_zone_id AS time_zo11_27_7_,
user6_.username AS usernam12_27_7_,
user7_.id AS id1_27_8_,
user7_.date_created AS date_cre2_27_8_,
user7_.date_last_update AS date_las3_27_8_,
user7_.created_by_id AS created13_27_8_,
user7_.last_update_by_id AS last_up14_27_8_,
user7_.display_name AS display_4_27_8_,
user7_.failed_login_attempts AS failed_l5_27_8_,
user7_.full_name AS full_nam6_27_8_,
user7_.note AS note7_27_8_,
user7_.object_status AS object_s8_27_8_,
user7_.password AS password9_27_8_,
user7_.phone AS phone10_27_8_,
user7_.time_zone_id AS time_zo11_27_8_,
user7_.username AS usernam12_27_8_,
provider8_.id AS id1_20_9_,
provider8_.date_created AS date_cre2_20_9_,
provider8_.date_last_update AS date_las3_20_9_,
provider8_.created_by_id AS created23_20_9_,
provider8_.last_update_by_id AS last_up24_20_9_,
provider8_.text_id_map AS text_id_4_20_9_,
provider8_.address_search_aid AS address_5_20_9_,
provider8_.alternate_country_id AS alterna25_20_9_,
provider8_.city_id AS city_id26_20_9_,
provider8_.lat AS lat6_20_9_,
provider8_.lng AS lng7_20_9_,
provider8_.street_line1 AS street_l8_20_9_,
provider8_.street_line2 AS street_l9_20_9_,
provider8_.zip AS zip10_20_9_,
provider8_.company_status AS company11_20_9_,
provider8_.compassion_level AS compass12_20_9_,
provider8_.emails AS emails13_20_9_,
provider8_.phones AS phones14_20_9_,
provider8_.social_media AS social_15_20_9_,
provider8_.urls AS urls16_20_9_,
provider8_.description AS descrip17_20_9_,
provider8_.importance AS importa18_20_9_,
provider8_.name AS name19_20_9_,
provider8_.object_status AS object_20_20_9_,
provider8_.parent_id AS parent_27_20_9_,
provider8_.search_aid AS search_21_20_9_,
provider8_.short_name AS short_n22_20_9_,
user9_.id AS id1_27_10_,
user9_.date_created AS date_cre2_27_10_,
user9_.date_last_update AS date_las3_27_10_,
user9_.created_by_id AS created13_27_10_,
user9_.last_update_by_id AS last_up14_27_10_,
user9_.display_name AS display_4_27_10_,
user9_.failed_login_attempts AS failed_l5_27_10_,
user9_.full_name AS full_nam6_27_10_,
user9_.note AS note7_27_10_,
user9_.object_status AS object_s8_27_10_,
user9_.password AS password9_27_10_,
user9_.phone AS phone10_27_10_,
user9_.time_zone_id AS time_zo11_27_10_,
user9_.username AS usernam12_27_10_,
user10_.id AS id1_27_11_,
user10_.date_created AS date_cre2_27_11_,
user10_.date_last_update AS date_las3_27_11_,
user10_.created_by_id AS created13_27_11_,
user10_.last_update_by_id AS last_up14_27_11_,
user10_.display_name AS display_4_27_11_,
user10_.failed_login_attempts AS failed_l5_27_11_,
user10_.full_name AS full_nam6_27_11_,
user10_.note AS note7_27_11_,
user10_.object_status AS object_s8_27_11_,
user10_.password AS password9_27_11_,
user10_.phone AS phone10_27_11_,
user10_.time_zone_id AS time_zo11_27_11_,
user10_.username AS usernam12_27_11_
FROM price_info prices0_
LEFT OUTER JOIN veg_user user1_ ON prices0_.created_by_id=user1_.id
LEFT OUTER JOIN veg_user user2_ ON user1_.created_by_id=user2_.id
LEFT OUTER JOIN veg_user user3_ ON user1_.last_update_by_id=user3_.id
LEFT OUTER JOIN veg_user user4_ ON prices0_.last_update_by_id=user4_.id
LEFT OUTER JOIN custom_currency customcurr5_ ON prices0_.currency_id=customcurr5_.id
LEFT OUTER JOIN veg_user user6_ ON customcurr5_.created_by_id=user6_.id
LEFT OUTER JOIN veg_user user7_ ON customcurr5_.last_update_by_id=user7_.id
LEFT OUTER JOIN provider provider8_ ON prices0_.provider_id=provider8_.id
LEFT OUTER JOIN veg_user user9_ ON provider8_.created_by_id=user9_.id
LEFT OUTER JOIN veg_user user10_ ON provider8_.last_update_by_id=user10_.id
WHERE prices0_.article_id = ?
Not sure about your objectives, however sometime following trick could help:
public class Article {
...
Set<Price> prices;
#Formula("select count(*) from price where article_id=:id")
private int priceCount;
public int getPriceCount() {
if (Hibernate.isInitialized(prices)) {
return prices == null ? 0 : prices.size();
}
return priceCount;
}
}

EclipseLink - Subqueries with Criteria Query (JPA)

take the following two tables as given:
Objects with columns objId, objTaxonId
Taxa with columns taxId, taxValidSynonymId, taxName (Note Taxa is plural for Taxon)
if a Taxon is valid, its id and validSynonymId are identical, otherwise they are different. To find all synonyms of a Taxon you 'only' need to find all Taxa where the taxValidSynonymId is filled with the taxId of the valid Taxon
how can i gain all Objects where the Taxon has a given Name (including their Synonyms?)
in SQL this is done in a few lines (and Minutes)
SELECT *
FROM Objects
WHERE objTaxonId IN (
SELECT taxId
FROM Taxa
WHERE taxName LIKE 'Test Taxon 1'
OR taxSynIdTaxon IN(
SELECT taxId
FROM Taxa
WHERE taxName LIKE 'Test Taxon 1'
)
)
i was able to work out the inside part, where i gain the list of Taxa and its Synonyms. Now i need to transform this Query to a Subquery...
String NAME_LIKE = "Test Taxon 1";
EntityManager em = EntityManagerProvider.getEntityManager("TestDB"); // get the EntityManager
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaxonImpl> cqObject = cb.createQuery(TaxonImpl.class);//
Root<TaxonImpl> taxonRoot = cqObject.from(TaxonImpl.class);//
Expression<String> taxon_name = taxonRoot.<String> get("taxName");
Predicate where = cb.equal(taxon_name, NAME_LIKE);
// subquery
Subquery<Integer> subQuery = cqObject.subquery(Integer.class);
Root<TaxonImpl> subRoot = subQuery.from(clsImpl);
subQuery.select(subRoot.<Integer> get("taxId"));
subQuery.where(cb.equal(subRoot.<String> get("taxName"), NAME_LIKE));
where = cb.or(where, taxonRoot.get("taxValidSynonymId").in(subQuery));
cqObject.where(where);
Query query = em.createQuery(cqObject);
List<TaxonImpl> result = query.getResultList();
NOTE: the Taxon is Mapped as an many to One relation (target-entity is TaxonImpl)
in my actual application the code (from the subquery) will be dynamically, so a Native Query does not help me.
i figured out how to "transform" the subquery into a query but Eclipselink threw me two errors
the first was forbidden access via field, when i tried the in on a result of TaxonImpl (i tried that first, as in my mapping files the Taxon is mapped as Entity.
so after this i tried to form the SQL 1:1 to JPA.
but Eclipselink generated something weird:
SELECT t0.objIdObject, t0.objAdminCreated, t0.objAdminCreator, t0.objAdminEdited, t0.objAdminEditor, t0.objAdminImport1, t0.objAdminImport2, t0.objAddBool1, t0.objAddBool2, t0.objAddBool3, t0.objAddBool4, t0.objAddBool5, t0.objAddDateTime1, t0.objAddDateTime2, t0.objCommonComments, t0.objCommonDescription, t0.objCommonKeywords, t0.objCommonName, t0.objCommonPublished, t0.objCommonPublishedAs, t0.objCommonStatus, t0.objCommonType, t0.objCommonTypustype, t0.objDetAccuracy, t0.objDetCf, t0.objDetComments, t0.objDetDate, t0.objDetMethod, t0.objDetResult, t0.objAddFloat1, t0.objAddFloat2, t0.objAddFloat3, t0.objAddFloat4, t0.objAddFloat5, t0.objEventAbundance, t0.objEventCollectionMethod, t0.objEventComments, t0.objEventMoreContacts, t0.objEventDateDay1, t0.objEventDate1, t0.objEventDateMonth1, t0.objEventDate2, t0.objEventDateUncertain, t0.objEventDateYear1, t0.objEventEcosystem, t0.objEventHabitat, t0.objEventNumber, t0.objEventPermission, t0.objEventSubstratum, t0.objEventTime1, t0.objEventTime2, t0.objEventWeekNumber, t0.objFlora, t0.objGuidObject, t0.objIOComments, t0.objIODeAccessed, t0.objAddInt1, t0.objAddInt2, t0.objAddInt3, t0.objAddInt4, t0.objAddInt5, t0.objStorageForeignNumber, t0.objStorageNumber, t0.objStorageNumberInCollection, t0.objStorageNumberOld, t0.objStorageNumberPrefix, t0.objAddLkp1, t0.objAddLkp10, t0.objAddLkp2, t0.objAddLkp3, t0.objAddLkp4, t0.objAddLkp5, t0.objAddLkp6, t0.objAddLkp7, t0.objAddLkp8, t0.objAddLkp9, t0.objAddLkpCs1, t0.objAddLkpCs10, t0.objAddLkpCs11, t0.objAddLkpCs12, t0.objAddLkpCs13, t0.objAddLkpCs14, t0.objAddLkpCs15, t0.objAddLkpCs2, t0.objAddLkpCs3, t0.objAddLkpCs4, t0.objAddLkpCs5, t0.objAddLkpCs6, t0.objAddLkpCs7, t0.objAddLkpCs8, t0.objAddLkpCs9, t0.objOriginAccessionDate, t0.objOriginAccessionNumber, t0.objOriginComments, t0.objOriginMoreContacts, t0.objOriginSource, t0.objOriginType, t0.objPreparationComments, t0.objPreparationDate, t0.objPreparationType, t0.objPropAdults, t0.objPropAge, t0.objPropAgeUnit, t0.objPropEggs, t0.objPropFemale, t0.objPropHeight, t0.objPropHeightUnit, t0.objPropJuveniles, t0.objPropLarvae, t0.objPropLength, t0.objPropLengthUnit, t0.objPropMale, t0.objPropObservation, t0.objPropObservationComments, t0.objPropPupae, t0.objPropSex, t0.objPropStadium, t0.objPropWeight, t0.objPropWeightUnit, t0.objPropWidth, t0.objPropWidthUnit, t0.objSiteComments, t0.objStorageComments, t0.objStorageContainerNumber, t0.objStorageContainerPieces, t0.objStorageContainerType, t0.objStorageLevel1, t0.objStorageLevel2, t0.objStorageLevel3, t0.objStorageLevel4, t0.objStorageLevel5, t0.objStorageNumberInContainer, t0.objstoragePieces, t0.objStorageValue, t0.objStorageValueUnit, t0.objAddText1, t0.objAddText10, t0.objAddText2, t0.objAddText3, t0.objAddText4, t0.objAddText5, t0.objAddText6, t0.objAddText7, t0.objAddText8, t0.objAddText9, t0.objIdCollection, t0.objCommonIdReference, t0.objDetIdContact, t0.objDetIdReference, t0.objEventIdContact, t0.objIdExcursion, t0.objOriginIdContact, t0.objPreparationIdContact, t0.objIdProject, t0.objSiteIdSite, t0.objdetIdTaxon
FROM tObjects t0
WHERE t0.objdetIdTaxon IN (
SELECT t1.taxIdTaxon.t1.taxIdTaxon
FROM tTaxa t1
WHERE (t1.taxTaxonDisplay LIKE 'Test Taxon 1'
OR t1.taxSynIdTaxon IN (
SELECT t2.taxSynIdTaxon
FROM tTaxa t2
WHERE t2.taxTaxonDisplay LIKE 'Test Taxon 1')))
to take out the error:
SELECT t1.taxIdTaxon.t1.taxIdTaxon
which is complete crap. you cannot execute a function on an type of int!
resolving this error (BUG?) introduces a new construct (which still returns the same results)
SELECT t1.objIdObject, t1.objAdminCreated, t1.objAdminCreator, t1.objAdminEdited, t1.objAdminEditor, t1.objAdminImport1, t1.objAdminImport2, t1.objAddBool1, t1.objAddBool2, t1.objAddBool3, t1.objAddBool4, t1.objAddBool5, t1.objAddDateTime1, t1.objAddDateTime2, t1.objCommonComments, t1.objCommonDescription, t1.objCommonKeywords, t1.objCommonName, t1.objCommonPublished, t1.objCommonPublishedAs, t1.objCommonStatus, t1.objCommonType, t1.objCommonTypustype, t1.objDetAccuracy, t1.objDetCf, t1.objDetComments, t1.objDetDate, t1.objDetMethod, t1.objDetResult, t1.objAddFloat1, t1.objAddFloat2, t1.objAddFloat3, t1.objAddFloat4, t1.objAddFloat5, t1.objEventAbundance, t1.objEventCollectionMethod, t1.objEventComments, t1.objEventMoreContacts, t1.objEventDateDay1, t1.objEventDate1, t1.objEventDateMonth1, t1.objEventDate2, t1.objEventDateUncertain, t1.objEventDateYear1, t1.objEventEcosystem, t1.objEventHabitat, t1.objEventNumber, t1.objEventPermission, t1.objEventSubstratum, t1.objEventTime1, t1.objEventTime2, t1.objEventWeekNumber, t1.objFlora, t1.objGuidObject, t1.objIOComments, t1.objIODeAccessed, t1.objAddInt1, t1.objAddInt2, t1.objAddInt3, t1.objAddInt4, t1.objAddInt5, t1.objStorageForeignNumber, t1.objStorageNumber, t1.objStorageNumberInCollection, t1.objStorageNumberOld, t1.objStorageNumberPrefix, t1.objAddLkp1, t1.objAddLkp10, t1.objAddLkp2, t1.objAddLkp3, t1.objAddLkp4, t1.objAddLkp5, t1.objAddLkp6, t1.objAddLkp7, t1.objAddLkp8, t1.objAddLkp9, t1.objAddLkpCs1, t1.objAddLkpCs10, t1.objAddLkpCs11, t1.objAddLkpCs12, t1.objAddLkpCs13, t1.objAddLkpCs14, t1.objAddLkpCs15, t1.objAddLkpCs2, t1.objAddLkpCs3, t1.objAddLkpCs4, t1.objAddLkpCs5, t1.objAddLkpCs6, t1.objAddLkpCs7, t1.objAddLkpCs8, t1.objAddLkpCs9, t1.objOriginAccessionDate, t1.objOriginAccessionNumber, t1.objOriginComments, t1.objOriginMoreContacts, t1.objOriginSource, t1.objOriginType, t1.objPreparationComments, t1.objPreparationDate, t1.objPreparationType, t1.objPropAdults, t1.objPropAge, t1.objPropAgeUnit, t1.objPropEggs, t1.objPropFemale, t1.objPropHeight, t1.objPropHeightUnit, t1.objPropJuveniles, t1.objPropLarvae, t1.objPropLength, t1.objPropLengthUnit, t1.objPropMale, t1.objPropObservation, t1.objPropObservationComments, t1.objPropPupae, t1.objPropSex, t1.objPropStadium, t1.objPropWeight, t1.objPropWeightUnit, t1.objPropWidth, t1.objPropWidthUnit, t1.objSiteComments, t1.objStorageComments, t1.objStorageContainerNumber, t1.objStorageContainerPieces, t1.objStorageContainerType, t1.objStorageLevel1, t1.objStorageLevel2, t1.objStorageLevel3, t1.objStorageLevel4, t1.objStorageLevel5, t1.objStorageNumberInContainer, t1.objstoragePieces, t1.objStorageValue, t1.objStorageValueUnit, t1.objAddText1, t1.objAddText10, t1.objAddText2, t1.objAddText3, t1.objAddText4, t1.objAddText5, t1.objAddText6, t1.objAddText7, t1.objAddText8, t1.objAddText9, t1.objIdCollection, t1.objCommonIdReference, t1.objDetIdContact, t1.objDetIdReference, t1.objEventIdContact, t1.objIdExcursion, t1.objOriginIdContact, t1.objPreparationIdContact, t1.objIdProject, t1.objSiteIdSite, t1.objdetIdTaxon
FROM tTaxa t0, tObjects t1
WHERE (
t0.taxIdTaxon IN (
SELECT t2.taxIdTaxon
FROM tTaxa t2
WHERE (t2.taxTaxonDisplay LIKE 'Test Taxon 1'
OR t2.taxSynIdTaxon IN (
SELECT t3.taxSynIdTaxon
FROM tTaxa t3
WHERE t3.taxTaxonDisplay LIKE 'Test Taxon 1'
)
)
) AND (t0.taxIdTaxon = t1.objdetIdTaxon)
)
this seems strange to me, but it is working - and it is faster than my alternative query, which includes a inner join
NOTE: Eclipselink does ignore the JoinType. regardless what you pass it takes an left outer join. (documentation says something else!)
finally i provide the two examples for join and joinless
private static Predicate addSynonymsWithJoins(Root<BioObjectImpl> r, CriteriaBuilder b, CriteriaQuery cq,
Attribute attr, Path path, Object value) {
Join taxJoin = r.join(BioObjectEnum.taxon.name(), JoinType.INNER);
Path<Object> taxValidSynonymId = taxJoin.get(TaxonEnum.validSynonymId.name());
Subquery<TaxonImpl> innerSubquery = cq.subquery(TaxonImpl.class);
Root fromSubTax = innerSubquery.from(TaxonImpl.class);
innerSubquery.select(fromSubTax.<Integer> get(TaxonEnum.id.name()));
Predicate dynamic1 = cb.like(fromSubTax.get(TaxonEnum.name.name()),
NAME_LIKE);
innerSubquery.where(dynamic1);
Predicate dynamic2 = resolveComparator(b, attr, taxJoin.get(attr.getPropertyName()), attr.getValue());//
Predicate p = b.or(taxValidSynonymId.in(innerSubquery), dynamic2);
return p;
}
private static Predicate addSynonymsWithoutJoins(Root<BioObjectImpl> r, CriteriaBuilder b, CriteriaQuery cq,
Attribute attr, Path path, Object value) {
cq.select(r);
Path<Integer> objTaxonId = r.<Integer> get(BioObjectEnum.taxon.name()).get(TaxonEnum.id.name());
Subquery<Integer> t2 = cq.subquery(Integer.class);
Root<TaxonImpl> t2fromTaxon = t2.from(TaxonImpl.class);
Path<Integer> t2taxId = t2fromTaxon.<Integer> get(TaxonEnum.validSynonymId.name());
t2.select(t2taxId);
Predicate t2dynamicWhere = resolveComparator(b, attr, t2fromTaxon.get(attr.getPropertyName()), attr.getValue());
t2.where(t2dynamicWhere);
Subquery<Integer> t1 = cq.subquery(Integer.class);
Root<TaxonImpl> t1fromTaxon = t1.from(TaxonImpl.class);
Predicate t1dynamicWhere = b.like(fromSubTax.get(TaxonEnum.name.name()),
NAME_LIKE);
Path<Integer> t1Select = t1fromTaxon.<Integer> get(TaxonEnum.id.name());
t1.select(t1Select);
Path<Integer> t1TaxSynonymId = t1fromTaxon.<Integer> get(TaxonEnum.validSynonymId.name());
t1dynamicWhere = b.or(t1dynamicWhere, t1TaxSynonymId.in(t2));
t1.where(t1dynamicWhere);
Predicate where = objTaxonId.in(t1);
return where;
}

Passing a parameter in a jpql query select

I have a jpql query instanciates a java object in select clause
public List<ChampEtatOT> getEtatOT(Date dateDebut, Date dateFin) {
Query query = em.createQuery("SELECT NEW ChampEtatOT( ot.numero, uo.denominationFr, ot.etat, ot.dateDebutReelle , ot.dateFinReelle, :dateParam1, :dateParam2, :dateParam3) FROM ordre ot JOIN ot.unite uo")
.setParameter("dateParam1", dateDebut, TemporalType.DATE)
.setParameter("dateParam2", dateFin, TemporalType.DATE)
.setParameter("dateParam3", new Date("2015-01-01"), TemporalType.DATE);
return query.getResultList();
}
I put 3 parameters, so i can pass it in the constructor
I get this error
Caused by: Exception [EclipseLink-6137] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.QueryExceptionException Description: An Exception was thrown while executing a ReportQuery with a constructor expression: java.lang.NoSuchMethodException: dz.elit.gmao.commun.reporting.classe.ChampEtatOT.<init>(java.lang.String, java.lang.String, java.lang.String, java.util.Date, java.util.Date)Query: ReportQuery(referenceClass=TravOrdreTravail jpql="SELECT NEW dz.elit.gmao.commun.reporting.classe.ChampEtatOT( ot.numero, uo.denominationFr, ot.etat, ot.dateDebutReelle , ot.dateFinReelle, :dateParam1, :dateParam2, :dateParam3) FROM TravOrdreTravail ot JOIN ot.uniteOrganisationnellle uo")
I think that it's not possible to put parameters in a select clause so does anyone have an idea, the constructor method is as follows:
public ChampEtatOT(String numero, String denominationFr, String etat, Date dateDebutReelle, Date dateFinReelle, Date dateParam1, Date dateParam2, Date dateParam3) {
this.numero = numero;
this.denominationFr = denominationFr;
if (etat.equals("OUV")) {
if (dateDebutReelle.before(dateParam1)) {
etatEntreeSortie = "En instance debut du mois";
} else {
if (dateDebutReelle.before(dateParam2)) {
etatEntreeSortie = "En instance fin du mois";
} else {
if (dateDebutReelle.after(dateParam1) && dateDebutReelle.before(dateParam2)) {
etatEntreeSortie = "Entree/Mois";
}
}
}
}
}
Problem solved, as you suggested bRIMOs Bor it's not possible to pass parameters in a SELECT clause, so i have retreived all the results in a List than filtered the results according to the three dates date1, date2, date3
Query query = em.createQuery("SELECT NEW ChampEtatAteliers"
+ "( ot.numero, uo.denominationFr, ot.etat, ot.dateDebutReelle, ot.dateFinReelle) "
+ "FROM ordre ot JOIN ot.unite uo");
List<ChampEtatAteliers> champEtatAtelierses = query.getResultList();
for (ChampEtatAteliers champEtatAtelierse : champEtatAtelierses) {
if (champEtatAtelierse.getDateDebutReelle().compareTo(date1) >= 0 && champEtatAtelierse.getDateDebutReelle().compareTo(date2) <= 0) {
champEtatAtelierList2.add(new ChampEtatAteliers(champEtatAtelierse.getNumero(), champEtatAtelierse.getDenominationFr(), "Entree/Mois"));
}
if (champEtatAtelierse.getEtat().equals("OUV")) {
if (champEtatAtelierse.getDateDebutReelle().compareTo(date1) < 0) {
champEtatAtelierse.setEtatEntreeSortie("En instance début du mois");
} else {
if (champEtatAtelierse.getDateDebutReelle().compareTo(date2) <= 0) {
champEtatAtelierse.setEtatEntreeSortie("En instance fin du mois");
}
}
}
}
I think that it's not possible to reference a parameter in the contructor.
in your case it throws a NoSuchMethodexeption : it means that, no method with the current signature in your ChampEtatOT class (5 parameters instead of 8 )
you can refer to this answer => Passing a parameter in a jpql query select
So ,try to retrive all data then make a filter method to set all the etatEntreeSortie values inside the ChampEtatOT class of the ResultList
Clearly the JPQL BNF does permit passing parameters as constructor arguments.
constructor_expression ::= NEW constructor_name ( constructor_item {, constructor_item}* )
constructor_item ::= single_valued_path_expression | scalar_expression | aggregate_expression |
identification_variable
scalar_expression ::= simple_arithmetic_expression | string_primary | enum_primary |
datetime_primary | boolean_primary | case_expression | entity_type_expression
string_primary ::= state_field_path_expression | string_literal |
input_parameter | functions_returning_strings | aggregate_expression | case_expression
i.e a scalar_expression can be a string_primary, which can be an input_parameter. So your JPA provider is not meeting the JPA spec and you should raise a bug on it.

Solr Custom Transfomer Not Working?

I am trying to Add Few Fields to solr Index While indexing with Data Import Handler.
Below is My data-config.xml
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/db" user="*****" password="*********"/>
<script><![CDATA[
function addMergedPdt(row)
{
var m = row.get('mergedPdt');
if(m == null)
{
row.put('mergedPdt',9999999999);
}
return row;
}
]]></script>
<script><![CDATA[
function transform(row)
{
if(row.get(mergedPdt) == null)
{
row.put('catStock', 0);
row.put('catPxMrp',0);
row.put('catPrice',0);
row.put('catCount',1)
row.put('catRating',0);
row.put('catAval',0);
return row;
}
else
{
row.put('catAval',1);
return row;
}
}
]]></script>
<document>
<entity name="product" onError="continue" transformer="script:addMergedPdt" query="select p.id, name, image, stock, lower(p.seller) as seller, brand,
cast(price as signed) as price, cast(pxMrp as signed) as pxMrp, mergedPdt, shipDays, url, cast(rating as signed) as rating,
disc(price, pxMrp) as discount, mc.node as seller_cat, oc.node as cat, substring_index(oc.node, '|', 1) as cat1,
substring(substring_index(oc.node, '|', 2), length(substring_index(oc.node, '|', 1)) + 2) as cat2,
substring(substring_index(oc.node, '|', 3), length(substring_index(oc.node, '|', 2)) + 2) as cat3
from _products as p, _mergedCat as mc, _ourCat as oc where active = 1 and cat_id = mc.id and ourCat = oc.id and
('${dataimporter.request.full}' != 'false' OR last_visited > '${dataimporter.last_index_time}') limit 10000">
<!-- To Papulate the Catalog Data -->
<entity name="mergedPdt" transformer="script:transform" onError="continue" query = "SELECT mergedPdt,count(*) as catCount,cast(max(stock) as signed) as catStock,cast(max(pxMrp) as signed) as catPxMrp,cast(min(price) as signed) as catPrice,cast(avg(rating) as signed) as catRating FROM `_products` where mergedPdt = ${product.mergedPdt}"/>
</entity>
I am Getting some Error Like
org.apache.solr.handler.dataimport.DataImportHandlerException: Error invoking script for entity mergedPdt Processing Document # 10000
at org.apache.solr.handler.dataimport.DataImportHandlerException.wrapAndThrow(DataImportHandlerException.java:70)
at org.apache.solr.handler.dataimport.ScriptTransformer.transformRow(ScriptTransformer.java:59)
at org.apache.solr.handler.dataimport.EntityProcessorWrapper.applyTransformer(EntityProcessorWrapper.java:198)
at org.apache.solr.handler.dataimport.EntityProcessorWrapper.nextRow(EntityProcessorWrapper.java:256)
at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:475)
at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:514)
at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:414)
at org.apache.solr.handler.dataimport.DocBuilder.doFullDump(DocBuilder.java:329)
at org.apache.solr.handler.dataimport.DocBuilder.execute(DocBuilder.java:232)
at org.apache.solr.handler.dataimport.DataImporter.doFullImport(DataImporter.java:416)
at org.apache.solr.handler.dataimport.DataImporter.runCmd(DataImporter.java:480)
at org.apache.solr.handler.dataimport.DataImporter$1.run(DataImporter.java:461)
Caused by: java.lang.NoSuchMethodException: no such method: transform
at com.sun.script.javascript.RhinoScriptEngine.invoke(RhinoScriptEngine.java:286)
at com.sun.script.javascript.RhinoScriptEngine.invokeFunction(RhinoScriptEngine.java:258)
at org.apache.solr.handler.dataimport.ScriptTransformer.transformRow(ScriptTransformer.java:55)
... 10 more
and all fields are being Indexed excluding the extra fields which i tried adding using the transformer.
And surprisingly only one field "catCount" has been indexed.
You can trust me and i am confident regarding the schema definition and other configurations.
any lead will be higly appriciated ??
Thanks in advance :)

memory leak occurs in hibernate while updating bean

I am getting error java.lang.OutOfMemoryError: Java heap space while i am updating profile detail of student..
error stack:
Hibernate: select studentbea0_.studentID as studentID7_42_, studentbea0_.studentFullName as studentF2_7_42_, studentbea0_.studentAddress as studentA3_7_42_, studentbea0_.studentCity as studentC4_7_42_, studentbea0_.studentState as studentS5_7_42_, studentbea0_.studentCountry as studentC6_7_42_, studentbea0_.className as className7_42_, studentbea0_.birthDate as birthDate7_42_, studentbea0_.studentContactNo as studentC9_7_42_, studentbea0_.studentPassword as student10_7_42_, studentbea0_.studentFacebookPage as student11_7_42_, studentbea0_.studentEmailId as student12_7_42_, studentbea0_.outsideuser as outside13_7_42_, studentbea0_.studentPhoto as student14_7_42_, studentbea0_.studentResume as student15_7_42_, studentbea0_.schooolName10 as schoool16_7_42_, studentbea0_.board10 as board17_7_42_, studentbea0_.marks10 as marks18_7_42_, studentbea0_.schooolName12 as schoool19_7_42_, studentbea0_.board12 as board20_7_42_, studentbea0_.marks12 as marks21_7_42_, studentbea0_.collegeNameUG as college22_7_42_, studentbea0_.boardUG as boardUG7_42_, studentbea0_.marksUG as marksUG7_42_, studentbea0_.collegeNamePG as college25_7_42_, studentbea0_.boardPG as boardPG7_42_, studentbea0_.marksPG as marksPG7_42_, studentbea0_.technologyknown as technol28_7_42_, studentbea0_.resume as resume7_42_, studentbea0_.date_time as date30_7_42_, studentbea0_.collegeID as collegeID7_42_, studentbea0_.courseID as courseID7_42_, collegebea1_.collegeid as collegeid0_0_, collegebea1_.collegeEmailID as collegeE2_0_0_, collegebea1_.collegename as collegen3_0_0_, collegebea1_.collegeaddress as collegea4_0_0_, collegebea1_.collegecity as collegec5_0_0_, collegebea1_.collegewebsite as collegew6_0_0_, collegebea1_.collegedescription as colleged7_0_0_, collegebea1_.collegecontactno as collegec8_0_0_, collegebea1_.collegepassword as collegep9_0_0_, collegebea1_.collegefacebookPage as college10_0_0_, collegebea1_.collegeState as college11_0_0_, collegebea1_.collegeCountry as college12_0_0_, collegebea1_.date_time as date13_0_0_, collegebea1_.pincode as pincode0_0_, college_co2_.collegeID as collegeID0_44_, college_co2_.college_course_ID as college1_44_, college_co2_.college_course_ID as college1_1_1_, college_co2_.date_time as date2_1_1_, college_co2_.courseID as courseID1_1_, college_co2_.collegeID as collegeID1_1_, testbean3_.collegeID as collegeID0_45_, testbean3_.testID as testID45_, testbean3_.testID as testID9_2_, testbean3_.testfile as testfile9_2_, testbean3_.questionSheet as question3_9_2_, testbean3_.teststatus as teststatus9_2_, testbean3_.totalmMark as totalmMark9_2_, testbean3_.time as time9_2_, testbean3_.type as type9_2_, testbean3_.testName as testName9_2_, testbean3_.examcode as examcode9_2_, testbean3_.description as descrip10_9_2_, testbean3_.students as students9_2_, testbean3_.date_time as date12_9_2_, testbean3_.collegeID as collegeID9_2_, testbean3_.subjectID as subjectID9_2_, testbean3_.facultyID as facultyID9_2_, collegeact4_.collegeID as collegeID0_46_, collegeact4_.sessionID as sessionID46_, collegeact4_.sessionID as sessionID23_3_, collegeact4_.loginTime as loginTime23_3_, collegeact4_.logoutTime as logoutTime23_3_, collegeact4_.ipAddress as ipAddress23_3_, collegeact4_.collegeID as collegeID23_3_, assignment5_.collegeID as collegeID0_47_, assignment5_.assignmentID as assignme1_47_, assignment5_.assignmentID as assignme1_17_4_, assignment5_.assignmentfile as assignme2_17_4_, assignment5_.assignmentstatus as assignme3_17_4_, assignment5_.assignmentName as assignme4_17_4_, assignment5_.description as descript5_17_4_, assignment5_.date_time as date6_17_4_, assignment5_.collegeID as collegeID17_4_, assignment5_.subjectID as subjectID17_4_, assignment5_.facultyID as facultyID17_4_, coursebean6_.courseid as courseid2_5_, coursebean6_.courseName as courseName2_5_, coursebean6_.noofsemester as noofseme3_2_5_, coursebean6_.date_time as date4_2_5_, subjectbea7_.courseID as courseID2_48_, subjectbea7_.subjectid as subjectid48_, subjectbea7_.subjectid as subjectid8_6_, subjectbea7_.subjectName as subjectN2_8_6_, subjectbea7_.semester as semester8_6_, subjectbea7_.practical as practical8_6_, subjectbea7_.date_time as date5_8_6_, subjectbea7_.courseID as courseID8_6_, faculty_su8_.courseID as courseID2_49_, faculty_su8_.faculty_subject_ID as faculty1_49_, faculty_su8_.faculty_subject_ID as faculty1_3_7_, faculty_su8_.date_time as date2_3_7_, faculty_su8_.courseID as courseID3_7_, faculty_su8_.subjectID as subjectID3_7_, faculty_su8_.facultyID as facultyID3_7_, college_co9_.courseID as courseID2_50_, college_co9_.college_course_ID as college1_50_, college_co9_.college_course_ID as college1_1_8_, college_co9_.date_time as date2_1_8_, college_co9_.courseID as courseID1_8_, college_co9_.collegeID as collegeID1_8_, jobcourseb10_.courseID as courseID2_51_, jobcourseb10_.jobcourseid as jobcours1_51_, jobcourseb10_.jobcourseid as jobcours1_26_9_, jobcourseb10_.courseID as courseID26_9_, jobcourseb10_.jobID as jobID26_9_, studentact11_.studentID as studentID7_52_, studentact11_.sessionID as sessionID52_, studentact11_.sessionID as sessionID22_10_, studentact11_.loginTime as loginTime22_10_, studentact11_.logoutTime as logoutTime22_10_, studentact11_.ipAddress as ipAddress22_10_, studentact11_.studentID as studentID22_10_, jobviewbea12_.studentID as studentID7_53_, jobviewbea12_.jobviewid as jobviewid53_, jobviewbea12_.jobviewid as jobviewid27_11_, jobviewbea12_.studentID as studentID27_11_, jobviewbea12_.jobID as jobID27_11_, jobbean13_.jobid as jobid20_12_, jobbean13_.jobtitle as jobtitle20_12_, jobbean13_.companyname as companyn3_20_12_, jobbean13_.description as descript4_20_12_, jobbean13_.experience as experience20_12_, jobbean13_.technologies as technolo6_20_12_, jobbean13_.designation as designat7_20_12_, jobbean13_.salary as salary20_12_, jobbean13_.bonus as bonus20_12_, jobbean13_.cities as cities20_12_, jobbean13_.vacancies as vacancies20_12_, jobbean13_.location as location20_12_, jobbean13_.jobtype as jobtype20_12_, jobbean13_.date_time as date14_20_12_, jobbean13_.recruiterID as recruit15_20_12_, jobbean13_.categoryTypeID as categor16_20_12_, jobbean13_.categoryID as categoryID20_12_, applyjobbe14_.studentID as studentID7_54_, applyjobbe14_.applyjobid as applyjobid54_, applyjobbe14_.applyjobid as applyjobid21_13_, applyjobbe14_.date_time as date2_21_13_, applyjobbe14_.studentID as studentID21_13_, applyjobbe14_.jobID as jobID21_13_, jobbean15_.jobid as jobid20_14_, jobbean15_.jobtitle as jobtitle20_14_, jobbean15_.companyname as companyn3_20_14_, jobbean15_.description as descript4_20_14_, jobbean15_.experience as experience20_14_, jobbean15_.technologies as technolo6_20_14_, jobbean15_.designation as designat7_20_14_, jobbean15_.salary as salary20_14_, jobbean15_.bonus as bonus20_14_, jobbean15_.cities as cities20_14_, jobbean15_.vacancies as vacancies20_14_, jobbean15_.location as location20_14_, jobbean15_.jobtype as jobtype20_14_, jobbean15_.date_time as date14_20_14_, jobbean15_.recruiterID as recruit15_20_14_, jobbean15_.categoryTypeID as categor16_20_14_, jobbean15_.categoryID as categoryID20_14_, likevideob16_.studentID as studentID7_55_, likevideob16_.likevideoid as likevide1_55_, likevideob16_.likevideoid as likevide1_31_15_, likevideob16_.date_time as date2_31_15_, likevideob16_.studentID as studentID31_15_, likevideob16_.videoID as videoID31_15_, videobean17_.videoid as videoid15_16_, videobean17_.videoname as videoname15_16_, videobean17_.description as descript3_15_16_, videobean17_.videopath as videopath15_16_, videobean17_.status as status15_16_, videobean17_.usertype as usertype15_16_, videobean17_.author as author15_16_, videobean17_.tag as tag15_16_, videobean17_.likedby as likedby15_16_, videobean17_.date_time as date10_15_16_, videobean17_.categoryID as categoryID15_16_, commentvid18_.studentID as studentID7_56_, commentvid18_.commentvideoid as commentv1_56_, commentvid18_.commentvideoid as commentv1_32_17_, commentvid18_.date_time as date2_32_17_, commentvid18_.comment as comment32_17_, commentvid18_.studentID as studentID32_17_, commentvid18_.videoID as videoID32_17_, videobean19_.videoid as videoid15_18_, videobean19_.videoname as videoname15_18_, videobean19_.description as descript3_15_18_, videobean19_.videopath as videopath15_18_, videobean19_.status as status15_18_, videobean19_.usertype as usertype15_18_, videobean19_.author as author15_18_, videobean19_.tag as tag15_18_, videobean19_.likedby as likedby15_18_, videobean19_.date_time as date10_15_18_, videobean19_.categoryID as categoryID15_18_, likequoteb20_.studentID as studentID7_57_, likequoteb20_.likequoteid as likequot1_57_, likequoteb20_.likequoteid as likequot1_44_19_, likequoteb20_.date_time as date2_44_19_, likequoteb20_.studentID as studentID44_19_, likequoteb20_.quoteid as quoteid44_19_, quotebean21_.quoteid as quoteid16_20_, quotebean21_.quotename as quotename16_20_, quotebean21_.description as descript3_16_20_, quotebean21_.quotepath as quotepath16_20_, quotebean21_.status as status16_20_, quotebean21_.usertype as usertype16_20_, quotebean21_.author as author16_20_, quotebean21_.date_time as date8_16_20_, quotebean21_.categoryID as categoryID16_20_, commentquo22_.studentID as studentID7_58_, commentquo22_.commentquoteid as commentq1_58_, commentquo22_.commentquoteid as commentq1_43_21_, commentquo22_.date_time as date2_43_21_, commentquo22_.comment as comment43_21_, commentquo22_.studentID as studentID43_21_, commentquo22_.quoteid as quoteid43_21_, quotebean23_.quoteid as quoteid16_22_, quotebean23_.quotename as quotename16_22_, quotebean23_.description as descript3_16_22_, quotebean23_.quotepath as quotepath16_22_, quotebean23_.status as status16_22_, quotebean23_.usertype as usertype16_22_, quotebean23_.author as author16_22_, quotebean23_.date_time as date8_16_22_, quotebean23_.categoryID as categoryID16_22_, likearticl24_.studentID as studentID7_59_, likearticl24_.likearticlesid as likearti1_59_, likearticl24_.likearticlesid as likearti1_38_23_, likearticl24_.date_time as date2_38_23_, likearticl24_.studentID as studentID38_23_, likearticl24_.articlesid as articlesid38_23_, articlesbe25_.articlesid as articlesid14_24_, articlesbe25_.articlesname as articles2_14_24_, articlesbe25_.description as descript3_14_24_, articlesbe25_.articlespath as articles4_14_24_, articlesbe25_.status as status14_24_, articlesbe25_.usertype as usertype14_24_, articlesbe25_.author as author14_24_, articlesbe25_.date_time as date8_14_24_, articlesbe25_.likedby as likedby14_24_, articlesbe25_.categoryID as categoryID14_24_, commentart26_.studentID as studentID7_60_, commentart26_.commentarticlesid as commenta1_60_, commentart26_.commentarticlesid as commenta1_37_25_, commentart26_.date_time as date2_37_25_, commentart26_.comment as comment37_25_, commentart26_.studentID as studentID37_25_, commentart26_.articlesID as articlesID37_25_, articlesbe27_.articlesid as articlesid14_26_, articlesbe27_.articlesname as articles2_14_26_, articlesbe27_.description as descript3_14_26_, articlesbe27_.articlespath as articles4_14_26_, articlesbe27_.status as status14_26_, articlesbe27_.usertype as usertype14_26_, articlesbe27_.author as author14_26_, articlesbe27_.date_time as date8_14_26_, articlesbe27_.likedby as likedby14_26_, articlesbe27_.categoryID as categoryID14_26_, likelifecl28_.studentID as studentID7_61_, likelifecl28_.likelifeclubvideoid as likelife1_61_, likelifecl28_.likelifeclubvideoid as likelife1_29_27_, likelifecl28_.date_time as date2_29_27_, likelifecl28_.studentID as studentID29_27_, likelifecl28_.videoid as videoid29_27_, lifeclubvi29_.videoid as videoid28_28_, lifeclubvi29_.videoname as videoname28_28_, lifeclubvi29_.description as descript3_28_28_, lifeclubvi29_.videopath as videopath28_28_, lifeclubvi29_.status as status28_28_, lifeclubvi29_.usertype as usertype28_28_, lifeclubvi29_.author as author28_28_, lifeclubvi29_.tag as tag28_28_, lifeclubvi29_.likedby as likedby28_28_, lifeclubvi29_.date_time as date10_28_28_, lifeclubvi29_.categoryID as categoryID28_28_, commentlif30_.studentID as studentID7_62_, commentlif30_.commentlifeclubvideoid as commentl1_62_, commentlif30_.commentlifeclubvideoid as commentl1_30_29_, commentlif30_.date_time as date2_30_29_, commentlif30_.comment as comment30_29_, commentlif30_.studentID as studentID30_29_, commentlif30_.videoid as videoid30_29_, lifeclubvi31_.videoid as videoid28_30_, lifeclubvi31_.videoname as videoname28_30_, lifeclubvi31_.description as descript3_28_30_, lifeclubvi31_.videopath as videopath28_30_, lifeclubvi31_.status as status28_30_, lifeclubvi31_.usertype as usertype28_30_, lifeclubvi31_.author as author28_30_, lifeclubvi31_.tag as tag28_30_, lifeclubvi31_.likedby as likedby28_30_, lifeclubvi31_.date_time as date10_28_30_, lifeclubvi31_.categoryID as categoryID28_30_, likeebookb32_.studentID as studentID7_63_, likeebookb32_.likeebookid as likeeboo1_63_, likeebookb32_.likeebookid as likeeboo1_33_31_, likeebookb32_.date_time as date2_33_31_, likeebookb32_.studentID as studentID33_31_, likeebookb32_.ebookID as ebookID33_31_, ebookbean33_.ebookid as ebookid13_32_, ebookbean33_.ebookname as ebookname13_32_, ebookbean33_.description as descript3_13_32_, ebookbean33_.ebookpath as ebookpath13_32_, ebookbean33_.status as status13_32_, ebookbean33_.usertype as usertype13_32_, ebookbean33_.author as author13_32_, ebookbean33_.likedby as likedby13_32_, ebookbean33_.date_time as date9_13_32_, ebookbean33_.categoryID as categoryID13_32_, commentebo34_.studentID as studentID7_64_, commentebo34_.commentebookid as commente1_64_, commentebo34_.commentebookid as commente1_34_33_, commentebo34_.date_time as date2_34_33_, commentebo34_.comment as comment34_33_, commentebo34_.studentID as studentID34_33_, commentebo34_.ebookID as ebookID34_33_, ebookbean35_.ebookid as ebookid13_34_, ebookbean35_.ebookname as ebookname13_34_, ebookbean35_.description as descript3_13_34_, ebookbean35_.ebookpath as ebookpath13_34_, ebookbean35_.status as status13_34_, ebookbean35_.usertype as usertype13_34_, ebookbean35_.author as author13_34_, ebookbean35_.likedby as likedby13_34_, ebookbean35_.date_time as date9_13_34_, ebookbean35_.categoryID as categoryID13_34_, submitassi36_.studentID as studentID7_65_, submitassi36_.submitassignmentid as submitas1_65_, submitassi36_.submitassignmentid as submitas1_18_35_, submitassi36_.date_time as date2_18_35_, submitassi36_.message as message18_35_, submitassi36_.assignmentfile as assignme4_18_35_, submitassi36_.studentID as studentID18_35_, submitassi36_.assignmentID as assignme6_18_35_, assignment37_.assignmentID as assignme1_17_36_, assignment37_.assignmentfile as assignme2_17_36_, assignment37_.assignmentstatus as assignme3_17_36_, assignment37_.assignmentName as assignme4_17_36_, assignment37_.description as descript5_17_36_, assignment37_.date_time as date6_17_36_, assignment37_.collegeID as collegeID17_36_, assignment37_.subjectID as subjectID17_36_, assignment37_.facultyID as facultyID17_36_, helpinghan38_.studentID as studentID7_66_, helpinghan38_.helpinghandID as helpingh1_66_, helpinghan38_.helpinghandID as helpingh1_46_37_, helpinghan38_.date_time as date2_46_37_, helpinghan38_.lastpostby as lastpostby46_37_, helpinghan38_.title as title46_37_, helpinghan38_.post as post46_37_, helpinghan38_.category as category46_37_, helpinghan38_.studentID as studentID46_37_, viewhelpin39_.helpinghandID as helpingh4_46_67_, viewhelpin39_.viewhelpinghandpostID as viewhelp1_67_, viewhelpin39_.viewhelpinghandpostID as viewhelp1_45_38_, viewhelpin39_.date_time as date2_45_38_, viewhelpin39_.studentID as studentID45_38_, viewhelpin39_.helpinghandID as helpingh4_45_38_, commenthel40_.helpinghandID as helpingh5_46_68_, commenthel40_.CommenthelpinghandpostID as Commenth1_68_, commenthel40_.CommenthelpinghandpostID as Commenth1_47_39_, commenthel40_.date_time as date2_47_39_, commenthel40_.comment as comment47_39_, commenthel40_.studentID as studentID47_39_, commenthel40_.helpinghandID as helpingh5_47_39_, viewhelpin41_.studentID as studentID7_69_, viewhelpin41_.viewhelpinghandpostID as viewhelp1_69_, viewhelpin41_.viewhelpinghandpostID as viewhelp1_45_40_, viewhelpin41_.date_time as date2_45_40_, viewhelpin41_.studentID as studentID45_40_, viewhelpin41_.helpinghandID as helpingh4_45_40_, commenthel42_.studentID as studentID7_70_, commenthel42_.CommenthelpinghandpostID as Commenth1_70_, commenthel42_.CommenthelpinghandpostID as Commenth1_47_41_, commenthel42_.date_time as date2_47_41_, commenthel42_.comment as comment47_41_, commenthel42_.studentID as studentID47_41_, commenthel42_.helpinghandID as helpingh5_47_41_ from student studentbea0_ inner join college collegebea1_ on studentbea0_.collegeID=collegebea1_.collegeid left outer join college_course college_co2_ on collegebea1_.collegeid=college_co2_.collegeID left outer join test testbean3_ on collegebea1_.collegeid=testbean3_.collegeID left outer join collegeactivitylog collegeact4_ on collegebea1_.collegeid=collegeact4_.collegeID left outer join assignment assignment5_ on collegebea1_.collegeid=assignment5_.collegeID inner join course coursebean6_ on studentbea0_.courseID=coursebean6_.courseid left outer join subject subjectbea7_ on coursebean6_.courseid=subjectbea7_.courseID left outer join faculty_subject faculty_su8_ on coursebean6_.courseid=faculty_su8_.courseID left outer join college_course college_co9_ on coursebean6_.courseid=college_co9_.courseID left outer join Job_Course jobcourseb10_ on coursebean6_.courseid=jobcourseb10_.courseID left outer join studentactivitylog studentact11_ on studentbea0_.studentID=studentact11_.studentID left outer join Job_View jobviewbea12_ on studentbea0_.studentID=jobviewbea12_.studentID left outer join job jobbean13_ on jobviewbea12_.jobID=jobbean13_.jobid left outer join applyjob applyjobbe14_ on studentbea0_.studentID=applyjobbe14_.studentID left outer join job jobbean15_ on applyjobbe14_.jobID=jobbean15_.jobid left outer join like_video likevideob16_ on studentbea0_.studentID=likevideob16_.studentID left outer join video videobean17_ on likevideob16_.videoID=videobean17_.videoid left outer join comment_video commentvid18_ on studentbea0_.studentID=commentvid18_.studentID left outer join video videobean19_ on commentvid18_.videoID=videobean19_.videoid left outer join like_quote likequoteb20_ on studentbea0_.studentID=likequoteb20_.studentID left outer join quote quotebean21_ on likequoteb20_.quoteid=quotebean21_.quoteid left outer join comment_quote commentquo22_ on studentbea0_.studentID=commentquo22_.studentID left outer join quote quotebean23_ on commentquo22_.quoteid=quotebean23_.quoteid left outer join like_articles likearticl24_ on studentbea0_.studentID=likearticl24_.studentID left outer join articles articlesbe25_ on likearticl24_.articlesid=articlesbe25_.articlesid left outer join comment_articles commentart26_ on studentbea0_.studentID=commentart26_.studentID left outer join articles articlesbe27_ on commentart26_.articlesID=articlesbe27_.articlesid left outer join like_lifeclubvideo likelifecl28_ on studentbea0_.studentID=likelifecl28_.studentID left outer join lifeclubvideo lifeclubvi29_ on likelifecl28_.videoid=lifeclubvi29_.videoid left outer join comment_lifeclubvideo commentlif30_ on studentbea0_.studentID=commentlif30_.studentID left outer join lifeclubvideo lifeclubvi31_ on commentlif30_.videoid=lifeclubvi31_.videoid left outer join like_ebook likeebookb32_ on studentbea0_.studentID=likeebookb32_.studentID left outer join ebook ebookbean33_ on likeebookb32_.ebookID=ebookbean33_.ebookid left outer join comment_ebook commentebo34_ on studentbea0_.studentID=commentebo34_.studentID left outer join ebook ebookbean35_ on commentebo34_.ebookID=ebookbean35_.ebookid left outer join submitassignment submitassi36_ on studentbea0_.studentID=submitassi36_.studentID left outer join assignment assignment37_ on submitassi36_.assignmentID=assignment37_.assignmentID left outer join helpinghand helpinghan38_ on studentbea0_.studentID=helpinghan38_.studentID left outer join ViewHelpingHandPostBean viewhelpin39_ on helpinghan38_.helpinghandID=viewhelpin39_.helpinghandID left outer join CommentHelpingHandPostBean commenthel40_ on helpinghan38_.helpinghandID=commenthel40_.helpinghandID left outer join ViewHelpingHandPostBean viewhelpin41_ on studentbea0_.studentID=viewhelpin41_.studentID left outer join CommentHelpingHandPostBean commenthel42_ on studentbea0_.studentID=commenthel42_.studentID where studentbea0_.studentID=?
Exception in thread "http-bio-8080-exec-9" java.lang.OutOfMemoryError: Java heap space
at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:1361)
at com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java:2333)
at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:435)
at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:2040)
at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:1443)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1777)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3249)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1268)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1403)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
at org.hibernate.loader.Loader.doQuery(Loader.java:802)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.loadEntity(Loader.java:2037)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:86)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:76)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3293)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:496)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:477)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:1005)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:998)
at com.dao.StudentService.updateEducationStudentProfile(StudentService.java:469)
at com.controller.Student.UpdateStudentProfileServlet.service(UpdateStudentProfileServlet.java:76)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
is it because of studentbean has many fields?
sometimes they give error "containerbackgroundprocessor".
This is happen only while i am updating studentprofile..
What is your JVM heap settings now ?
How much data do you load from the DB?
Try
-Xms 512m -Xmx 1028m -XX:PermSize=128m -XX:MaxPermSize=512m

Categories

Resources