Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate - unable to find Entity with ID

I'm retreiving some data from the database in my DAO with this method :

@Override
@Transactional
public List<History> findLastHistoriesByCount(int gHistoriesCount) {

    List<History> result = new ArrayList<History>();
    result = entityManager
            .createQuery(
                    "SELECT h FROM History h ORDER BY h.eventDate DESC",
                    History.class).setMaxResults(gHistoriesCount).getResultList();

    return result;
}

and this is my History Class :

public class History implements Serializable {

...

@ManyToOne
@JoinColumn(name = "ID_CONTRACT_HISTORY", nullable = true)
private ContractHistory contractHistory;

@ManyToOne
@JoinColumn(name = "ID_SALARY_HISTORY", nullable = true)
private SalaryHistory salaryHistory;

...
}

but I'm facing this exception :

javax.persistence.EntityNotFoundException: Unable to find com.xxx.model.ContractHistory with id 108

While I'm sure I have that row in my database in the table ContractHistory

EDIT

I've already seen the solution with @NotFound annotation and I don't want it cause it's just a bypass for me cause my data is there !! and I want to retreive it.

EDIT 2 **ContractHistory : **

public class ContractHistory extends implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
...
}

EDIT 3 :

ContractHistory : (Don't mind the table names I've changed it before only for this question :

enter image description here

History :

enter image description here

EDIT 4

The sql query just before the exception :

 Hibernate: 
22:22:29,211 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)     select
22:22:29,211 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon0_.id as id234_13_,
22:22:29,212 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon0_.ID_COMPANY_CONTRACT as ID3_234_13_,
22:22:29,212 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon0_.ID_COMPANY_CONTRACT_AVENANT as ID4_234_13_,
22:22:29,212 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon0_.ID_EVENT_TYPE as ID5_234_13_,
22:22:29,213 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon0_.timestamp as timestamp234_13_,
22:22:29,213 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon0_.ID_USER as ID6_234_13_,
22:22:29,213 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon1_.id as id218_0_,
22:22:29,214 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon1_.IDCLIENT as IDCLIENT218_0_,
22:22:29,214 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon1_.endDate as endDate218_0_,
22:22:29,215 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon1_.invoicePaymentDay as invoiceP3_218_0_,
22:22:29,215 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon1_.percentage_Extra_Hours as percentage4_218_0_,
22:22:29,216 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon1_.IDPROFILE as IDPROFILE218_0_,
22:22:29,216 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon1_.rate as rate218_0_,
22:22:29,216 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon1_.reference as reference218_0_,
22:22:29,217 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon1_.secondRate as secondRate218_0_,
22:22:29,217 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon1_.startDate as startDate218_0_,
22:22:29,218 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon1_.thirdRate as thirdRate218_0_,
22:22:29,218 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon1_.UPDATE_TIMESTAMP as UPDATE10_218_0_,
22:22:29,218 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon1_.IDUSER as IDUSER218_0_,
22:22:29,219 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         client2_.id as id215_1_,
22:22:29,219 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         client2_.address as address215_1_,
22:22:29,219 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         client2_.BILLING_ADDRESS as BILLING3_215_1_,
22:22:29,220 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         client2_.CLIENT_NAME as CLIENT4_215_1_,
22:22:29,220 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         client2_.COMMENTS as COMMENTS215_1_,
22:22:29,220 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         client2_.IDCOMPANY as IDCOMPANY215_1_,
22:22:29,221 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         client2_.logo as logo215_1_,
22:22:29,221 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         client2_.siren as siren215_1_,
22:22:29,222 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         client2_.TVA_INTRACOMMUNAUTAIRE as TVA8_215_1_,
22:22:29,222 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         client2_.UPDATE_TIMESTAMP as UPDATE9_215_1_,
22:22:29,222 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         client2_.IDZIPCODE as IDZIPCODE215_1_,
22:22:29,223 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile3_.id as id178_2_,
22:22:29,223 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile3_.CV_FILENAME_PATH as CV2_178_2_,
22:22:29,223 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile3_.birthdate as birthdate178_2_,
22:22:29,224 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile3_.IDCIVILITY as IDCIVILITY178_2_,
22:22:29,225 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile3_.IDCOMPANY as IDCOMPANY178_2_,
22:22:29,225 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile3_.IDCOUNTRY as IDCOUNTRY178_2_,
22:22:29,226 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile3_.deleted as deleted178_2_,
22:22:29,226 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile3_.disponibility as disponib5_178_2_,
22:22:29,226 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile3_.ENTRANCE_DATE as ENTRANCE6_178_2_,
22:22:29,227 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile3_.EXIT_DATE as EXIT7_178_2_,
22:22:29,227 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile3_.EXTERNE as EXTERNE178_2_,
22:22:29,227 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile3_.firstname as firstname178_2_,
22:22:29,228 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile3_.IMMEDIATE_DISPONIBILITY as IMMEDIATE10_178_2_,
22:22:29,228 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile3_.lastname as lastname178_2_,
22:22:29,228 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile3_.mail as mail178_2_,
22:22:29,228 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile3_.OWNER as OWNER178_2_,
22:22:29,229 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile3_.photo as photo178_2_,
22:22:29,229 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile3_.SOCIALESECURITYCODE as SOCIALE14_178_2_,
22:22:29,230 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile3_.UPDATE_TIMESTAMP as UPDATE15_178_2_,
22:22:29,230 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile3_.IDZIPCODE as IDZIPCODE178_2_,
22:22:29,230 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user4_.id as id165_3_,
22:22:29,231 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user4_.IDCIVILITY as IDCIVILITY165_3_,
22:22:29,231 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user4_.ID_COMPANY as ID10_165_3_,
22:22:29,231 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user4_.Fax_Number as Fax2_165_3_,
22:22:29,232 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user4_.First_Name as First3_165_3_,
22:22:29,232 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user4_.Last_Name as Last4_165_3_,
22:22:29,232 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user4_.Mail_Address as Mail5_165_3_,
22:22:29,233 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user4_.password as password165_3_,
22:22:29,233 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user4_.phone_Number as phone7_165_3_,
22:22:29,233 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user4_.photo as photo165_3_,
22:22:29,234 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user4_.IDPROFILE as IDPROFILE165_3_,
22:22:29,234 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user4_.IDUSERROLE as IDUSERROLE165_3_,
22:22:29,235 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon5_.id as id219_4_,
22:22:29,235 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon5_.ID_COMPANY_CONTRACT as ID11_219_4_,
22:22:29,235 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon5_.dateAvenant as dateAven2_219_4_,
22:22:29,236 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon5_.endDate as endDate219_4_,
22:22:29,236 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon5_.invoicePaymentDay as invoiceP4_219_4_,
22:22:29,236 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon5_.rate as rate219_4_,
22:22:29,237 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon5_.reference as reference219_4_,
22:22:29,237 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon5_.secondRate as secondRate219_4_,
22:22:29,238 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon5_.startDate as startDate219_4_,
22:22:29,238 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon5_.thirdRate as thirdRate219_4_,
22:22:29,238 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon5_.UPDATE_TIMESTAMP as UPDATE10_219_4_,
22:22:29,239 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon5_.IDUSER as IDUSER219_4_,
22:22:29,239 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon6_.id as id218_5_,
22:22:29,239 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon6_.IDCLIENT as IDCLIENT218_5_,
22:22:29,240 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon6_.endDate as endDate218_5_,
22:22:29,240 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon6_.invoicePaymentDay as invoiceP3_218_5_,
22:22:29,240 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon6_.percentage_Extra_Hours as percentage4_218_5_,
22:22:29,241 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon6_.IDPROFILE as IDPROFILE218_5_,
22:22:29,241 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon6_.rate as rate218_5_,
22:22:29,241 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon6_.reference as reference218_5_,
22:22:29,242 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon6_.secondRate as secondRate218_5_,
22:22:29,242 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon6_.startDate as startDate218_5_,
22:22:29,242 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon6_.thirdRate as thirdRate218_5_,
22:22:29,242 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon6_.UPDATE_TIMESTAMP as UPDATE10_218_5_,
22:22:29,243 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon6_.IDUSER as IDUSER218_5_,
22:22:29,243 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user7_.id as id165_6_,
22:22:29,243 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user7_.IDCIVILITY as IDCIVILITY165_6_,
22:22:29,243 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user7_.ID_COMPANY as ID10_165_6_,
22:22:29,243 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user7_.Fax_Number as Fax2_165_6_,
22:22:29,244 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user7_.First_Name as First3_165_6_,
22:22:29,244 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user7_.Last_Name as Last4_165_6_,
22:22:29,244 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user7_.Mail_Address as Mail5_165_6_,
22:22:29,246 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user7_.password as password165_6_,
22:22:29,246 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user7_.phone_Number as phone7_165_6_,
22:22:29,246 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user7_.photo as photo165_6_,
22:22:29,247 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user7_.IDPROFILE as IDPROFILE165_6_,
22:22:29,247 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user7_.IDUSERROLE as IDUSERROLE165_6_,
22:22:29,247 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon8_.id as id233_7_,
22:22:29,247 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon8_.CODE_EVENT_TYPE as CODE2_233_7_,
22:22:29,247 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon8_.libelle as libelle233_7_,
22:22:29,248 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user9_.id as id165_8_,
22:22:29,248 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user9_.IDCIVILITY as IDCIVILITY165_8_,
22:22:29,248 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user9_.ID_COMPANY as ID10_165_8_,
22:22:29,248 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user9_.Fax_Number as Fax2_165_8_,
22:22:29,249 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user9_.First_Name as First3_165_8_,
22:22:29,249 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user9_.Last_Name as Last4_165_8_,
22:22:29,249 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user9_.Mail_Address as Mail5_165_8_,
22:22:29,250 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user9_.password as password165_8_,
22:22:29,250 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user9_.phone_Number as phone7_165_8_,
22:22:29,250 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user9_.photo as photo165_8_,
22:22:29,251 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user9_.IDPROFILE as IDPROFILE165_8_,
22:22:29,251 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user9_.IDUSERROLE as IDUSERROLE165_8_,
22:22:29,252 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         civility10_.id as id167_9_,
22:22:29,252 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         civility10_.civility as civility167_9_,
22:22:29,253 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         company11_.id as id169_10_,
22:22:29,253 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         company11_.ID_TYPE as ID12_169_10_,
22:22:29,253 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         company11_.companyname as companyn2_169_10_,
22:22:29,253 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         company11_.CONTACT_MAIL as CONTACT3_169_10_,
22:22:29,254 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         company11_.CONTACT_NAME as CONTACT4_169_10_,
22:22:29,254 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         company11_.CONTACT_PHONE as CONTACT5_169_10_,
22:22:29,254 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         company11_.description as descript6_169_10_,
22:22:29,254 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         company11_.logo as logo169_10_,
22:22:29,255 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         company11_.siren as siren169_10_,
22:22:29,255 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         company11_.staffing as staffing169_10_,
22:22:29,255 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         company11_.street as street169_10_,
22:22:29,256 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         company11_.website as website169_10_,
22:22:29,256 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         company11_.IDZIPCODE as IDZIPCODE169_10_,
22:22:29,257 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile12_.id as id178_11_,
22:22:29,257 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile12_.CV_FILENAME_PATH as CV2_178_11_,
22:22:29,257 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile12_.birthdate as birthdate178_11_,
22:22:29,257 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile12_.IDCIVILITY as IDCIVILITY178_11_,
22:22:29,258 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile12_.IDCOMPANY as IDCOMPANY178_11_,
22:22:29,258 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile12_.IDCOUNTRY as IDCOUNTRY178_11_,
22:22:29,258 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile12_.deleted as deleted178_11_,
22:22:29,259 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile12_.disponibility as disponib5_178_11_,
22:22:29,259 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile12_.ENTRANCE_DATE as ENTRANCE6_178_11_,
22:22:29,259 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile12_.EXIT_DATE as EXIT7_178_11_,
22:22:29,259 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile12_.EXTERNE as EXTERNE178_11_,
22:22:29,260 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile12_.firstname as firstname178_11_,
22:22:29,260 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile12_.IMMEDIATE_DISPONIBILITY as IMMEDIATE10_178_11_,
22:22:29,260 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile12_.lastname as lastname178_11_,
22:22:29,260 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile12_.mail as mail178_11_,
22:22:29,261 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile12_.OWNER as OWNER178_11_,
22:22:29,261 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile12_.photo as photo178_11_,
22:22:29,261 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile12_.SOCIALESECURITYCODE as SOCIALE14_178_11_,
22:22:29,261 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile12_.UPDATE_TIMESTAMP as UPDATE15_178_11_,
22:22:29,262 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile12_.IDZIPCODE as IDZIPCODE178_11_,
22:22:29,262 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         userrole13_.id as id217_12_,
22:22:29,262 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         userrole13_.LABEL as LABEL217_12_ 
22:22:29,262 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)     from
22:22:29,262 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         company_contract_history companycon0_ 
22:22:29,263 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)     inner join
22:22:29,263 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         company_contract companycon1_ 
22:22:29,263 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)             on companycon0_.ID_COMPANY_CONTRACT=companycon1_.id 
22:22:29,263 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)     left outer join
22:22:29,263 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         client client2_ 
22:22:29,264 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)             on companycon1_.IDCLIENT=client2_.id 
22:22:29,264 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)     left outer join
22:22:29,264 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile profile3_ 
22:22:29,264 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)             on companycon1_.IDPROFILE=profile3_.id 
22:22:29,264 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)     left outer join
22:22:29,265 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user user4_ 
22:22:29,265 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)             on companycon1_.IDUSER=user4_.id 
22:22:29,265 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)     inner join
22:22:29,265 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         company_contract_avenant companycon5_ 
22:22:29,265 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)             on companycon0_.ID_COMPANY_CONTRACT_AVENANT=companycon5_.id 
22:22:29,266 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)     left outer join
22:22:29,266 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         company_contract companycon6_ 
22:22:29,266 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)             on companycon5_.ID_COMPANY_CONTRACT=companycon6_.id 
22:22:29,266 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)     left outer join
22:22:29,266 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user user7_ 
22:22:29,267 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)             on companycon5_.IDUSER=user7_.id 
22:22:29,267 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)     inner join
22:22:29,267 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         company_contract_event_type companycon8_ 
22:22:29,267 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)             on companycon0_.ID_EVENT_TYPE=companycon8_.id 
22:22:29,267 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)     inner join
22:22:29,268 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user user9_ 
22:22:29,268 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)             on companycon0_.ID_USER=user9_.id 
22:22:29,268 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)     left outer join
22:22:29,268 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         civility civility10_ 
22:22:29,268 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)             on user9_.IDCIVILITY=civility10_.id 
22:22:29,269 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)     left outer join
22:22:29,269 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         company company11_ 
22:22:29,269 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)             on user9_.ID_COMPANY=company11_.id 
22:22:29,269 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)     left outer join
22:22:29,269 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         profile profile12_ 
22:22:29,270 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)             on user9_.IDPROFILE=profile12_.id 
22:22:29,270 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)     left outer join
22:22:29,270 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         user_role userrole13_ 
22:22:29,270 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)             on user9_.IDUSERROLE=userrole13_.id 
22:22:29,270 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)     where
22:22:29,271 INFO  [stdout] (http-localhost-127.0.0.1-8888-1)         companycon0_.id=?

22:22:29,273 GRAVE [org.zkoss] (http-localhost-127.0.0.1-8888-1) : javax.persistence.EntityNotFoundException: Unable to find com.epro.model.CompanyContractHistory with id 108

EDIT 5 :

I changed the query to : "SELECT gb FROM GlobalHistory gb LEFT JOIN FETCH gb.companyContractHistory cc where gb.id = 544 and cc.id = 108"

And with that I did get the line !! (Notice I'm using JOIN FETCH), any one care to explain ?

like image 330
Moatez Bouhdid Avatar asked Oct 06 '17 19:10

Moatez Bouhdid


2 Answers

try with:

@ManyToOne(fetch = FetchType.LAZY)
@NotFound(action = NotFoundAction.IGNORE)
like image 63
Khalil M Avatar answered Oct 05 '22 12:10

Khalil M


I found the solution :

In my ContractHistory I have :

public class ContractHistory extends implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;

@ManyToOne(optional = false)
@JoinColumn(name="ID_COMPANY_CONTRACT", nullable = true)
private CompanyContract companyContract;

...
}

Once I removed optinal = false I did get the data without Any Problem.

FIW : When you make the association mandatory (i.e. optional=false), it trusts you and assumes that an address exists, since the association is mandatory. So it directly populates the address field with a proxy, knowing that there is an address referencing the person (SOF)

like image 31
Moatez Bouhdid Avatar answered Oct 05 '22 13:10

Moatez Bouhdid