-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Problem with OneToMany annotation on delete
PostPosted: Tue Jan 19, 2010 4:09 am 
Newbie

Joined: Thu Jan 22, 2009 2:49 am
Posts: 13
Hello

I am having 2 classes :

Code:
public class Employee  implements Serializable {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "EMPLOYEE_ID")
    private Integer id;

    @Column(name = "EMPLOYEE_REGISTRATION_NUMBER")
    private String registrationNumber;

    @OneToMany(targetEntity=EmployeeAccusation.class, cascade = CascadeType.ALL)
    @OrderBy("date")
    @JoinColumn(name = "EMPLOYEE_ID")
    @org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.FALSE)
    @org.hibernate.annotations.Cascade(value={org.hibernate.annotations.CascadeType.DELETE})
    private List accusations =  new ArrayList();
...
}

and
Code:
@Table(name = "EMPLOYEE_ACCUSATION")
public class EmployeeAccusation implements Serializable{
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "EMPLOYEE_ACCUSATION_ID")
    private Integer id;

    @Column(name = "EMPLOYEE_ACCUSATION_DATE")
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date date;

    @Column(name = "EMPLOYEE_ACCUSATION_DESCRIPTION")
    private String description;

    @Column(name = "EMPLOYEE_ACCUSATION_EPONYM")
    @org.hibernate.annotations.Type(type="yes_no")
    private Boolean eponym = false;

    @ManyToOne(targetEntity=Employee.class, fetch=FetchType.EAGER)
    @JoinColumn(name = "EMPLOYEE_ID")
    private Employee employee = new Employee();

.....
}


everything works fine but when i am trying to delete an object from Employee class i am getting the following error
Code:
org.hibernate.exception.ConstraintViolationException: could not delete collection: [gr.mnec.personnel.model.Employee.accusations#1]
   org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
   org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
   org.hibernate.persister.collection.AbstractCollectionPersister.remove(AbstractCollectionPersister.java:1093)
   org.hibernate.action.CollectionRemoveAction.execute(CollectionRemoveAction.java:107)
   org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
....
java.sql.SQLIntegrityConstraintViolationException: Column 'EMPLOYEE_ID'  cannot accept a NULL value.
   org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
   org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
....
org.apache.derby.client.am.SqlException: Column 'EMPLOYEE_ID'  cannot accept a NULL value.
   org.apache.derby.client.am.Statement.completeExecute(Unknown Source)
   org.apache.derby.client.net.NetStatementReply.parseEXCSQLSTTreply(Unknown Source)
   org.apache.derby.client.net.NetStatementReply.readExecute(Unknown Source)
....


I think hibernate tryes not to delete the object EmployeeAccusation but only the assosision between Employee and EmployeeAccusation.
What is the wrong with Annotations?


Top
 Profile  
 
 Post subject: Re: Problem with OneToMany annotation on delete
PostPosted: Tue Jan 19, 2010 6:52 am 
Regular
Regular

Joined: Thu Dec 10, 2009 10:53 am
Posts: 50
I think it should work. Can you post the generated SQL?


Top
 Profile  
 
 Post subject: Re: Problem with OneToMany annotation on delete
PostPosted: Tue Jan 19, 2010 7:20 am 
Newbie

Joined: Thu Jan 22, 2009 2:49 am
Posts: 13
Hibernate:
select
employee0_.EMPLOYEE_ID as EMPLOYEE1_0_,
employee0_.EMPLOYEE_FAX as EMPLOYEE2_0_,
employee0_.EMPLOYEE_PHONE as EMPLOYEE3_0_,
employee0_.EMPLOYEE_CITY as EMPLOYEE4_0_,
employee0_.EMPLOYEE_STREET as EMPLOYEE5_0_,
employee0_.EMPLOYEE_ZIPCODE as EMPLOYEE6_0_,
employee0_.EMPLOYEE_FATHER_NAME as EMPLOYEE7_0_,
employee0_.EMPLOYEE_FIRST_NAME as EMPLOYEE8_0_,
employee0_.EMPLOYEE_LAST_NAME as EMPLOYEE9_0_,
employee0_.EMPLOYEE_SEX as EMPLOYEE10_0_,
employee0_.EMPLOYEE_REGISTRATION_NUMBER as EMPLOYEE11_0_
from
EMPLOYEE employee0_
where
employee0_.EMPLOYEE_ID=?

Hibernate:
select
transfers0_.EMPLOYEE_ID as EMPLOYEE6_4_,
transfers0_.EMPLOYEE_TRANSFER_ID as EMPLOYEE1_4_,
transfers0_.EMPLOYEE_TRANSFER_ID as EMPLOYEE1_10_3_,
transfers0_.EMPLOYEE_TRANSFER_DATE_COMMUNICATION as EMPLOYEE2_10_3_,
transfers0_.EMPLOYEE_TRANSFER_DATE_FINISH as EMPLOYEE3_10_3_,
transfers0_.EMPLOYEE_TRANSFER_DATE_START as EMPLOYEE4_10_3_,
transfers0_.DESCRIPTION as DESCRIPT5_10_3_,
transfers0_.EMPLOYEE_ID as EMPLOYEE6_10_3_,
transfers0_.EMPLOYEE_TRANSFER_TAX_OFFICE_ID as EMPLOYEE7_10_3_,
transfers0_.EMPLOYEE_TRANSFER_TYPE_ID as EMPLOYEE8_10_3_,
taxoffice1_.TAX_OFFICE_ID as TAX1_18_0_,
taxoffice1_.TAX_OFFICE_CODE as TAX2_18_0_,
taxoffice1_.TAX_OFFICE_FAX as TAX3_18_0_,
taxoffice1_.TAX_OFFICE_PHONE as TAX4_18_0_,
taxoffice1_.TAX_OFFICE_CITY as TAX5_18_0_,
taxoffice1_.TAX_OFFICE_STREET as TAX6_18_0_,
taxoffice1_.TAX_OFFICE_ZIPCODE as TAX7_18_0_,
taxoffice1_.TAX_OFFICE_NAME as TAX8_18_0_,
taxoffice1_.TAX_OFFICE_TYPE_ID as TAX9_18_0_,
taxofficet2_.TAX_OFFICE_TYPE_ID as TAX1_19_1_,
taxofficet2_.TAX_OFFICE_TYPE_NAME as TAX2_19_1_,
transferty3_.TRANSFER_TYPE_ID as TRANSFER1_16_2_,
transferty3_.TRANSFER_TYPE_NAME as TRANSFER2_16_2_,
transferty3_.TRANSFER_TYPE_PERMANENT as TRANSFER3_16_2_
from
EMPLOYEE_TRANSFER transfers0_
left outer join
TAX_OFFICE taxoffice1_
on transfers0_.EMPLOYEE_TRANSFER_TAX_OFFICE_ID=taxoffice1_.TAX_OFFICE_ID
left outer join
TAX_OFFICE_TYPE taxofficet2_
on taxoffice1_.TAX_OFFICE_TYPE_ID=taxofficet2_.TAX_OFFICE_TYPE_ID
left outer join
TRANSFER_TYPE transferty3_
on transfers0_.EMPLOYEE_TRANSFER_TYPE_ID=transferty3_.TRANSFER_TYPE_ID
where
transfers0_.EMPLOYEE_ID=?
order by
transfers0_.EMPLOYEE_TRANSFER_DATE_FINISH asc

Hibernate:
select
specialiti0_.EMPLOYEE_ID as EMPLOYEE3_2_,
specialiti0_.EMPLOYEE_SPECIALITY_ID as EMPLOYEE1_2_,
specialiti0_.EMPLOYEE_SPECIALITY_ID as EMPLOYEE1_2_1_,
specialiti0_.SPECIALITY_DATE as SPECIALITY2_2_1_,
specialiti0_.EMPLOYEE_ID as EMPLOYEE3_2_1_,
specialiti0_.EMPLOYEE_SPECIALITY_TYPE_ID as EMPLOYEE4_2_1_,
speciality1_.SPECIALITY_TYPE_ID as SPECIALITY1_14_0_,
speciality1_.SPECIALITY_TYPE_NAME as SPECIALITY2_14_0_
from
EMPLOYEE_SPECIALITY specialiti0_
left outer join
SPECIALITY_TYPE speciality1_
on specialiti0_.EMPLOYEE_SPECIALITY_TYPE_ID=speciality1_.SPECIALITY_TYPE_ID
where
specialiti0_.EMPLOYEE_ID=?
order by
specialiti0_.SPECIALITY_DATE asc

Hibernate:
select
seminars0_.EMPLOYEE_ID as EMPLOYEE5_1_,
seminars0_.EMPLOYEE_SEMINAR_ID as EMPLOYEE1_1_,
seminars0_.EMPLOYEE_SEMINAR_ID as EMPLOYEE1_6_0_,
seminars0_.EMPLOYEE_SEMINAR_DATE_FINISH as EMPLOYEE2_6_0_,
seminars0_.EMPLOYEE_SEMINAR_DATE_START as EMPLOYEE3_6_0_,
seminars0_.EMPLOYEE_ID as EMPLOYEE5_6_0_,
seminars0_.EMPLOYEE_SEMINAR_TITLE as EMPLOYEE4_6_0_
from
EMPLOYEE_SEMINAR seminars0_
where
seminars0_.EMPLOYEE_ID=?
order by
seminars0_.EMPLOYEE_SEMINAR_DATE_START asc

Hibernate:
select
medicals0_.EMPLOYEE_ID as EMPLOYEE4_1_,
medicals0_.EMPLOYEE_MEDICAL_ID as EMPLOYEE1_1_,
medicals0_.EMPLOYEE_MEDICAL_ID as EMPLOYEE1_8_0_,
medicals0_.EMPLOYEE_MEDICAL_DATE as EMPLOYEE2_8_0_,
medicals0_.EMPLOYEE_MEDICAL_DESCRIPTION as EMPLOYEE3_8_0_,
medicals0_.EMPLOYEE_ID as EMPLOYEE4_8_0_
from
EMPLOYEE_MEDICAL medicals0_
where
medicals0_.EMPLOYEE_ID=?
order by
medicals0_.EMPLOYEE_MEDICAL_DATE asc

Hibernate:
select
languages0_.EMPLOYEE_ID as EMPLOYEE4_2_,
languages0_.EMPLOYEE_LANGUAGE_ID as EMPLOYEE1_2_,
languages0_.EMPLOYEE_LANGUAGE_ID as EMPLOYEE1_5_1_,
languages0_.EMPLOYEE_LANGUAGE_DATE as EMPLOYEE2_5_1_,
languages0_.EMPLOYEE_ID as EMPLOYEE4_5_1_,
languages0_.EMPLOYEE_LANGUAGE_TITLE as EMPLOYEE3_5_1_,
languages0_.EMPLOYEE_LANGUAGE_TYPE_ID as EMPLOYEE5_5_1_,
languagety1_.LANGUAGE_TYPE_ID as LANGUAGE1_15_0_,
languagety1_.LANGUAGE_TYPE_CODE as LANGUAGE2_15_0_,
languagety1_.LANGUAGE_TYPE_NAME as LANGUAGE3_15_0_
from
EMPLOYEE_LANGUAGE languages0_
left outer join
LANGUAGE_TYPE languagety1_
on languages0_.EMPLOYEE_LANGUAGE_TYPE_ID=languagety1_.LANGUAGE_TYPE_ID
where
languages0_.EMPLOYEE_ID=?
order by
languages0_.EMPLOYEE_LANGUAGE_DATE asc

Hibernate:
select
educations0_.EMPLOYEE_ID as EMPLOYEE4_1_,
educations0_.EMPLOYEE_EDUCATION_ID as EMPLOYEE1_1_,
educations0_.EMPLOYEE_EDUCATION_ID as EMPLOYEE1_4_0_,
educations0_.EMPLOYEE_EDUCATION_DATE as EMPLOYEE2_4_0_,
educations0_.EMPLOYEE_ID as EMPLOYEE4_4_0_,
educations0_.EMPLOYEE_EDUCATION_TITLE as EMPLOYEE3_4_0_
from
EMPLOYEE_EDUCATION educations0_
where
educations0_.EMPLOYEE_ID=?
order by
educations0_.EMPLOYEE_EDUCATION_DATE asc

Hibernate:
select
disciplina0_.EMPLOYEE_ID as EMPLOYEE4_1_,
disciplina0_.EMPLOYEE_DISCIPLINARY_ID as EMPLOYEE1_1_,
disciplina0_.EMPLOYEE_DISCIPLINARY_ID as EMPLOYEE1_9_0_,
disciplina0_.EMPLOYEE_DISCIPLINARY_DATE as EMPLOYEE2_9_0_,
disciplina0_.EMPLOYEE_DISCIPLINARY_DESCRIPTION as EMPLOYEE3_9_0_,
disciplina0_.EMPLOYEE_ID as EMPLOYEE4_9_0_
from
EMPLOYEE_DISCIPLINARY disciplina0_
where
disciplina0_.EMPLOYEE_ID=?
order by
disciplina0_.EMPLOYEE_DISCIPLINARY_DATE asc

Hibernate:
select
degrees0_.EMPLOYEE_ID as EMPLOYEE3_2_,
degrees0_.EMPLOYEE_DEGREE_ID as EMPLOYEE1_2_,
degrees0_.EMPLOYEE_DEGREE_ID as EMPLOYEE1_3_1_,
degrees0_.DEGREE_DATE as DEGREE2_3_1_,
degrees0_.EMPLOYEE_ID as EMPLOYEE3_3_1_,
degrees0_.EMPLOYEE_DEGREE_TYPE_ID as EMPLOYEE4_3_1_,
degreetype1_.DEGREE_TYPE_ID as DEGREE1_12_0_,
degreetype1_.DEGREE_TYPE_NAME as DEGREE2_12_0_
from
EMPLOYEE_DEGREE degrees0_
left outer join
DEGREE_TYPE degreetype1_
on degrees0_.EMPLOYEE_DEGREE_TYPE_ID=degreetype1_.DEGREE_TYPE_ID
where
degrees0_.EMPLOYEE_ID=?
order by
degrees0_.DEGREE_DATE asc

Hibernate:
select
categories0_.EMPLOYEE_ID as EMPLOYEE3_2_,
categories0_.EMPLOYEE_CATEGORY_ID as EMPLOYEE1_2_,
categories0_.EMPLOYEE_CATEGORY_ID as EMPLOYEE1_1_1_,
categories0_.CATEGORY_DATE as CATEGORY2_1_1_,
categories0_.EMPLOYEE_ID as EMPLOYEE3_1_1_,
categories0_.EMPLOYEE_CATEGORY_TYPE_ID as EMPLOYEE4_1_1_,
categoryty1_.CATEGORY_TYPE_ID as CATEGORY1_13_0_,
categoryty1_.CATEGORY_TYPE_NAME as CATEGORY2_13_0_
from
EMPLOYEE_CATEGORY categories0_
left outer join
CATEGORY_TYPE categoryty1_
on categories0_.EMPLOYEE_CATEGORY_TYPE_ID=categoryty1_.CATEGORY_TYPE_ID
where
categories0_.EMPLOYEE_ID=?
order by
categories0_.CATEGORY_DATE asc

Hibernate:
select
accusation0_.EMPLOYEE_ID as EMPLOYEE5_1_,
accusation0_.EMPLOYEE_ACCUSATION_ID as EMPLOYEE1_1_,
accusation0_.EMPLOYEE_ACCUSATION_ID as EMPLOYEE1_7_0_,
accusation0_.EMPLOYEE_ACCUSATION_DATE as EMPLOYEE2_7_0_,
accusation0_.EMPLOYEE_ACCUSATION_DESCRIPTION as EMPLOYEE3_7_0_,
accusation0_.EMPLOYEE_ID as EMPLOYEE5_7_0_,
accusation0_.EMPLOYEE_ACCUSATION_EPONYM as EMPLOYEE4_7_0_
from
EMPLOYEE_ACCUSATION accusation0_
where
accusation0_.EMPLOYEE_ID=?
order by
accusation0_.EMPLOYEE_ACCUSATION_DATE asc
Code:
Hibernate:
    update
        EMPLOYEE_ACCUSATION
    set
        EMPLOYEE_ID=null
    where
        EMPLOYEE_ID=?



I think the problem is on [coded] lines
The class Employee has many others associassions


Top
 Profile  
 
 Post subject: Re: Problem with OneToMany annotation on delete
PostPosted: Mon Feb 08, 2010 10:26 am 
Newbie

Joined: Thu Jan 22, 2009 2:49 am
Posts: 13
Solved using the followin declaration

Code:
....
   
    @OneToMany(targetEntity=EmployeeAccusation.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy="employee")
    @OrderBy("date")
    @JoinColumn(name = "EMPLOYEE_ID")
    private Set accusations =  new HashSet();       
....


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.