0

I've been working with JPA and Spring and encountered a problem with removing Entity. An attempt to remove following Entity results fail with the Error Stack Trace placed below. I suspect that i have to do something with fields in @JoinColumn annotation, but what?

Entity:

@Entity
public class Customers {

    @Id
    @GeneratedValue
    private int id;

    private String name;
    private int age;
    @Column(name="spend_money")
    private Double spendMoney;

    @OneToOne(cascade=CascadeType.ALL)
    @JoinColumn(name="contact_id")
    private Contacts contact;

    @ManyToOne
    @JoinColumn(name="country_id")
    private Country country;

    @OneToOne(cascade=CascadeType.ALL)
    @JoinColumn(name="address_id")
    private Address address;

    @OneToMany(fetch = FetchType.EAGER, mappedBy="customer")
    private Set<Purchase> purchases = new HashSet<Purchase>();

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Double getSpendMoney() {
        return spendMoney;
    }

    public void setSpendMoney(Double spendMoney) {
        this.spendMoney = spendMoney;
    }

    public Contacts getContact() {
        return contact;
    }

    public void setContact(Contacts contact) {
        this.contact = contact;
    }

    public Country getCountry() {
        return country;
    }

    public void setCountry(Country country) {
        this.country = country;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }


    public Set<Purchase> getPurchases() {
        return purchases;
    }

    public void setPurchases(Set<Purchase> purchases) {
        this.purchases = purchases;
    }

    @Override
    public String toString() {
        return "Customers [id=" + id + ", name=" + name + ", age=" + age
                + ", spendMoney=" + spendMoney + ", contact=" + contact
                + ", country=" + country + ", address=" + address
                + ", purchases=" + purchases + "]";
    }


}

Address Entity:

@Entity
public class Address {

    @Id
    @GeneratedValue
    private int id;

    private String city;
    @Column(name="postal_code")
    private String postalCode;

    private String street;

    @ManyToOne
    @JoinColumn(name="country_id")
    private Country country;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getPostalCode() {
        return postalCode;
    }

    public void setPostalCode(String postalCode) {
        this.postalCode = postalCode;
    }

    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    public Country getCountry() {
        return country;
    }

    public void setCountry(Country country) {
        this.country = country;
    }

    @Override
    public String toString() {
        return "Address [id=" + id + ", city=" + city + ", postalCode="
                + postalCode + ", street=" + street + ", country=" + country
                + "]";
    }



}

Contacts Entity:

@Entity
public class Contacts {

    @Id
    @GeneratedValue
    private int id;

    @Column(name="phone_number")
    private String phoneNumber;

    private String email;

    @OneToOne
    @JoinColumn(name="address_id")
    private Address address;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    @Override
    public String toString() {
        return "Contacts [id=" + id + ", phoneNumber=" + phoneNumber
                + ", email=" + email + ", address=" + address + "]";
    }


}

Country Entity:

@Entity
@Table(name="country")
public class Country {

    @Id
    @GeneratedValue
    private int id;

    @Column
    private String country;

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "country")
    private Set<Customers> customers = new HashSet<Customers>(0);

    @OneToMany(fetch = FetchType.EAGER, mappedBy="country")
    private Set<Address> addresses;


    public Set<Customers> getCustomers() {
        return customers;
    }

    public void setCustomers(Set<Customers> customers) {
        this.customers = customers;
    }

    public Set<Address> getAddresses() {
        return addresses;
    }

    public void setAddresses(Set<Address> addresses) {
        this.addresses = addresses;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    @Override
    public String toString() {
        return "Country [id=" + id + ", country=" + country + "]";
    }

}

Controller's method responsible for removing the Entity:

@RequestMapping(value = "/user/remove/{id}")
    public String removeUser(@PathVariable int id) {
        Customers customer = customersDetailsDAO.getCustomer(id);
        logger.info(Integer.toString(customer.getAddress().getId()));
        customersDetailsDAO.removeCustomer(customer);
        return "users";

    }

And the dao method:

@Override
    public void removeCustomer(Customers customer) {
        em.remove(em.merge(customer));

    }

Stack trace:

Hibernate: select customers0_.id as id1_2_, customers0_.address_id as address_5_2_, customers0_.age as age2_2_, customers0_.contact_id as contact_6_2_, customers0_.country_id as country_7_2_, customers0_.name as name3_2_, customers0_.spend_money as spend_mo4_2_ from Customers customers0_
Hibernate: select address0_.id as id1_0_0_, address0_.city as city2_0_0_, address0_.country_id as country_5_0_0_, address0_.postal_code as postal_c3_0_0_, address0_.street as street4_0_0_, country1_.id as id1_4_1_, country1_.country as country2_4_1_, customers2_.country_id as country_7_4_2_, customers2_.id as id1_2_2_, customers2_.id as id1_2_3_, customers2_.address_id as address_5_2_3_, customers2_.age as age2_2_3_, customers2_.contact_id as contact_6_2_3_, customers2_.country_id as country_7_2_3_, customers2_.name as name3_2_3_, customers2_.spend_money as spend_mo4_2_3_ from Address address0_ left outer join country country1_ on address0_.country_id=country1_.id left outer join Customers customers2_ on country1_.id=customers2_.country_id where address0_.id=?
Hibernate: select contacts0_.id as id1_1_0_, contacts0_.address_id as address_4_1_0_, contacts0_.email as email2_1_0_, contacts0_.phone_number as phone_nu3_1_0_, address1_.id as id1_0_1_, address1_.city as city2_0_1_, address1_.country_id as country_5_0_1_, address1_.postal_code as postal_c3_0_1_, address1_.street as street4_0_1_, country2_.id as id1_4_2_, country2_.country as country2_4_2_ from Contacts contacts0_ left outer join Address address1_ on contacts0_.address_id=address1_.id left outer join country country2_ on address1_.country_id=country2_.id where contacts0_.id=?
Hibernate: select address0_.id as id1_0_0_, address0_.city as city2_0_0_, address0_.country_id as country_5_0_0_, address0_.postal_code as postal_c3_0_0_, address0_.street as street4_0_0_, country1_.id as id1_4_1_, country1_.country as country2_4_1_, customers2_.country_id as country_7_4_2_, customers2_.id as id1_2_2_, customers2_.id as id1_2_3_, customers2_.address_id as address_5_2_3_, customers2_.age as age2_2_3_, customers2_.contact_id as contact_6_2_3_, customers2_.country_id as country_7_2_3_, customers2_.name as name3_2_3_, customers2_.spend_money as spend_mo4_2_3_ from Address address0_ left outer join country country1_ on address0_.country_id=country1_.id left outer join Customers customers2_ on country1_.id=customers2_.country_id where address0_.id=?
Hibernate: select contacts0_.id as id1_1_0_, contacts0_.address_id as address_4_1_0_, contacts0_.email as email2_1_0_, contacts0_.phone_number as phone_nu3_1_0_, address1_.id as id1_0_1_, address1_.city as city2_0_1_, address1_.country_id as country_5_0_1_, address1_.postal_code as postal_c3_0_1_, address1_.street as street4_0_1_, country2_.id as id1_4_2_, country2_.country as country2_4_2_ from Contacts contacts0_ left outer join Address address1_ on contacts0_.address_id=address1_.id left outer join country country2_ on address1_.country_id=country2_.id where contacts0_.id=?
Hibernate: select purchases0_.customer_id as customer4_2_0_, purchases0_.id as id1_3_0_, purchases0_.id as id1_3_1_, purchases0_.customer_id as customer4_3_1_, purchases0_.date as date2_3_1_, purchases0_.value as value3_3_1_ from Purchase purchases0_ where purchases0_.customer_id=?
Hibernate: select purchases0_.customer_id as customer4_2_0_, purchases0_.id as id1_3_0_, purchases0_.id as id1_3_1_, purchases0_.customer_id as customer4_3_1_, purchases0_.date as date2_3_1_, purchases0_.value as value3_3_1_ from Purchase purchases0_ where purchases0_.customer_id=?
Hibernate: select purchasedp0_.purchase_id as purchase5_3_0_, purchasedp0_.id as id1_7_0_, purchasedp0_.id as id1_7_1_, purchasedp0_.amount as amount2_7_1_, purchasedp0_.product_id as product_4_7_1_, purchasedp0_.purchase_id as purchase5_7_1_, purchasedp0_.value as value3_7_1_, product1_.id as id1_5_2_, product1_.category_id as category4_5_2_, product1_.name as name2_5_2_, product1_.price as price3_5_2_, productcat2_.id as id1_6_3_, productcat2_.category as category2_6_3_ from purchase_products purchasedp0_ left outer join product product1_ on purchasedp0_.product_id=product1_.id left outer join product_category productcat2_ on product1_.category_id=productcat2_.id where purchasedp0_.purchase_id=?
Hibernate: select products0_.category_id as category4_6_0_, products0_.id as id1_5_0_, products0_.id as id1_5_1_, products0_.category_id as category4_5_1_, products0_.name as name2_5_1_, products0_.price as price3_5_1_ from product products0_ where products0_.category_id=?
Hibernate: select addresses0_.country_id as country_5_4_0_, addresses0_.id as id1_0_0_, addresses0_.id as id1_0_1_, addresses0_.city as city2_0_1_, addresses0_.country_id as country_5_0_1_, addresses0_.postal_code as postal_c3_0_1_, addresses0_.street as street4_0_1_ from Address addresses0_ where addresses0_.country_id=?
Hibernate: select customers0_.id as id1_2_0_, customers0_.address_id as address_5_2_0_, customers0_.age as age2_2_0_, customers0_.contact_id as contact_6_2_0_, customers0_.country_id as country_7_2_0_, customers0_.name as name3_2_0_, customers0_.spend_money as spend_mo4_2_0_, address1_.id as id1_0_1_, address1_.city as city2_0_1_, address1_.country_id as country_5_0_1_, address1_.postal_code as postal_c3_0_1_, address1_.street as street4_0_1_, country2_.id as id1_4_2_, country2_.country as country2_4_2_, contacts3_.id as id1_1_3_, contacts3_.address_id as address_4_1_3_, contacts3_.email as email2_1_3_, contacts3_.phone_number as phone_nu3_1_3_, address4_.id as id1_0_4_, address4_.city as city2_0_4_, address4_.country_id as country_5_0_4_, address4_.postal_code as postal_c3_0_4_, address4_.street as street4_0_4_, country5_.id as id1_4_5_, country5_.country as country2_4_5_, purchases6_.customer_id as customer4_2_6_, purchases6_.id as id1_3_6_, purchases6_.id as id1_3_7_, purchases6_.customer_id as customer4_3_7_, purchases6_.date as date2_3_7_, purchases6_.value as value3_3_7_, purchasedp7_.purchase_id as purchase5_3_8_, purchasedp7_.id as id1_7_8_, purchasedp7_.id as id1_7_9_, purchasedp7_.amount as amount2_7_9_, purchasedp7_.product_id as product_4_7_9_, purchasedp7_.purchase_id as purchase5_7_9_, purchasedp7_.value as value3_7_9_ from Customers customers0_ left outer join Address address1_ on customers0_.address_id=address1_.id left outer join country country2_ on address1_.country_id=country2_.id left outer join Contacts contacts3_ on customers0_.contact_id=contacts3_.id left outer join Address address4_ on contacts3_.address_id=address4_.id left outer join country country5_ on customers0_.country_id=country5_.id left outer join Purchase purchases6_ on customers0_.id=purchases6_.customer_id left outer join purchase_products purchasedp7_ on purchases6_.id=purchasedp7_.purchase_id where customers0_.id=?
Hibernate: select customers0_.country_id as country_7_4_0_, customers0_.id as id1_2_0_, customers0_.id as id1_2_1_, customers0_.address_id as address_5_2_1_, customers0_.age as age2_2_1_, customers0_.contact_id as contact_6_2_1_, customers0_.country_id as country_7_2_1_, customers0_.name as name3_2_1_, customers0_.spend_money as spend_mo4_2_1_, address1_.id as id1_0_2_, address1_.city as city2_0_2_, address1_.country_id as country_5_0_2_, address1_.postal_code as postal_c3_0_2_, address1_.street as street4_0_2_, country2_.id as id1_4_3_, country2_.country as country2_4_3_, contacts3_.id as id1_1_4_, contacts3_.address_id as address_4_1_4_, contacts3_.email as email2_1_4_, contacts3_.phone_number as phone_nu3_1_4_, address4_.id as id1_0_5_, address4_.city as city2_0_5_, address4_.country_id as country_5_0_5_, address4_.postal_code as postal_c3_0_5_, address4_.street as street4_0_5_ from Customers customers0_ left outer join Address address1_ on customers0_.address_id=address1_.id left outer join country country2_ on address1_.country_id=country2_.id left outer join Contacts contacts3_ on customers0_.contact_id=contacts3_.id left outer join Address address4_ on contacts3_.address_id=address4_.id where customers0_.country_id=?
Hibernate: select purchases0_.customer_id as customer4_2_0_, purchases0_.id as id1_3_0_, purchases0_.id as id1_3_1_, purchases0_.customer_id as customer4_3_1_, purchases0_.date as date2_3_1_, purchases0_.value as value3_3_1_ from Purchase purchases0_ where purchases0_.customer_id=?
Hibernate: select purchasedp0_.purchase_id as purchase5_3_0_, purchasedp0_.id as id1_7_0_, purchasedp0_.id as id1_7_1_, purchasedp0_.amount as amount2_7_1_, purchasedp0_.product_id as product_4_7_1_, purchasedp0_.purchase_id as purchase5_7_1_, purchasedp0_.value as value3_7_1_, product1_.id as id1_5_2_, product1_.category_id as category4_5_2_, product1_.name as name2_5_2_, product1_.price as price3_5_2_, productcat2_.id as id1_6_3_, productcat2_.category as category2_6_3_ from purchase_products purchasedp0_ left outer join product product1_ on purchasedp0_.product_id=product1_.id left outer join product_category productcat2_ on product1_.category_id=productcat2_.id where purchasedp0_.purchase_id=?
Hibernate: select products0_.category_id as category4_6_0_, products0_.id as id1_5_0_, products0_.id as id1_5_1_, products0_.category_id as category4_5_1_, products0_.name as name2_5_1_, products0_.price as price3_5_1_ from product products0_ where products0_.category_id=?
Hibernate: select addresses0_.country_id as country_5_4_0_, addresses0_.id as id1_0_0_, addresses0_.id as id1_0_1_, addresses0_.city as city2_0_1_, addresses0_.country_id as country_5_0_1_, addresses0_.postal_code as postal_c3_0_1_, addresses0_.street as street4_0_1_ from Address addresses0_ where addresses0_.country_id=?
INFO : pl.hibernate.basics.controllers.HomeController - 2
Hibernate: select customers0_.id as id1_2_2_, customers0_.address_id as address_5_2_2_, customers0_.age as age2_2_2_, customers0_.contact_id as contact_6_2_2_, customers0_.country_id as country_7_2_2_, customers0_.name as name3_2_2_, customers0_.spend_money as spend_mo4_2_2_, address1_.id as id1_0_0_, address1_.city as city2_0_0_, address1_.country_id as country_5_0_0_, address1_.postal_code as postal_c3_0_0_, address1_.street as street4_0_0_, contacts2_.id as id1_1_1_, contacts2_.address_id as address_4_1_1_, contacts2_.email as email2_1_1_, contacts2_.phone_number as phone_nu3_1_1_ from Customers customers0_ left outer join Address address1_ on customers0_.address_id=address1_.id left outer join Contacts contacts2_ on customers0_.contact_id=contacts2_.id where customers0_.id=?
Hibernate: select country0_.id as id1_4_0_, country0_.country as country2_4_0_ from country country0_ where country0_.id=?
Hibernate: select purchases0_.customer_id as customer4_2_0_, purchases0_.id as id1_3_0_, purchases0_.id as id1_3_1_, purchases0_.customer_id as customer4_3_1_, purchases0_.date as date2_3_1_, purchases0_.value as value3_3_1_ from Purchase purchases0_ where purchases0_.customer_id=?
Hibernate: select customers0_.country_id as country_7_4_0_, customers0_.id as id1_2_0_, customers0_.id as id1_2_1_, customers0_.address_id as address_5_2_1_, customers0_.age as age2_2_1_, customers0_.contact_id as contact_6_2_1_, customers0_.country_id as country_7_2_1_, customers0_.name as name3_2_1_, customers0_.spend_money as spend_mo4_2_1_, address1_.id as id1_0_2_, address1_.city as city2_0_2_, address1_.country_id as country_5_0_2_, address1_.postal_code as postal_c3_0_2_, address1_.street as street4_0_2_, country2_.id as id1_4_3_, country2_.country as country2_4_3_, contacts3_.id as id1_1_4_, contacts3_.address_id as address_4_1_4_, contacts3_.email as email2_1_4_, contacts3_.phone_number as phone_nu3_1_4_, address4_.id as id1_0_5_, address4_.city as city2_0_5_, address4_.country_id as country_5_0_5_, address4_.postal_code as postal_c3_0_5_, address4_.street as street4_0_5_ from Customers customers0_ left outer join Address address1_ on customers0_.address_id=address1_.id left outer join country country2_ on address1_.country_id=country2_.id left outer join Contacts contacts3_ on customers0_.contact_id=contacts3_.id left outer join Address address4_ on contacts3_.address_id=address4_.id where customers0_.country_id=?
Hibernate: select purchases0_.customer_id as customer4_2_0_, purchases0_.id as id1_3_0_, purchases0_.id as id1_3_1_, purchases0_.customer_id as customer4_3_1_, purchases0_.date as date2_3_1_, purchases0_.value as value3_3_1_ from Purchase purchases0_ where purchases0_.customer_id=?
Hibernate: select purchasedp0_.purchase_id as purchase5_3_0_, purchasedp0_.id as id1_7_0_, purchasedp0_.id as id1_7_1_, purchasedp0_.amount as amount2_7_1_, purchasedp0_.product_id as product_4_7_1_, purchasedp0_.purchase_id as purchase5_7_1_, purchasedp0_.value as value3_7_1_, product1_.id as id1_5_2_, product1_.category_id as category4_5_2_, product1_.name as name2_5_2_, product1_.price as price3_5_2_, productcat2_.id as id1_6_3_, productcat2_.category as category2_6_3_ from purchase_products purchasedp0_ left outer join product product1_ on purchasedp0_.product_id=product1_.id left outer join product_category productcat2_ on product1_.category_id=productcat2_.id where purchasedp0_.purchase_id=?
Hibernate: select products0_.category_id as category4_6_0_, products0_.id as id1_5_0_, products0_.id as id1_5_1_, products0_.category_id as category4_5_1_, products0_.name as name2_5_1_, products0_.price as price3_5_1_ from product products0_ where products0_.category_id=?
Hibernate: select addresses0_.country_id as country_5_4_0_, addresses0_.id as id1_0_0_, addresses0_.id as id1_0_1_, addresses0_.city as city2_0_1_, addresses0_.country_id as country_5_0_1_, addresses0_.postal_code as postal_c3_0_1_, addresses0_.street as street4_0_1_ from Address addresses0_ where addresses0_.country_id=?
Hibernate: update Contacts set address_id=?, email=?, phone_number=? where id=?

SEVERE: Servlet.service() for servlet [appServlet] in context with path [/basics] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement] with root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'address_id' cannot be null
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:400)
    at com.mysql.jdbc.Util.getInstance(Util.java:383)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3847)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3783)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2447)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2594)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1901)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2113)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2049)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2034)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
    at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:62)
    at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3281)
    at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3183)
    at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3525)
    at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:159)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:465)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:351)
    at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350)
    at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)
    at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1258)
    at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:425)
    at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
    at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:177)
    at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:77)
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:513)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:755)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:724)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:475)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:270)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at com.sun.proxy.$Proxy99.removeCustomer(Unknown Source)
    at pl.hibernate.basics.controllers.HomeController.removeUser(HomeController.java:148)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
Kavv
  • 209
  • 2
  • 12
  • you didn't post the controller which remove this entity – Jérémie B Feb 06 '16 at 21:34
  • @JérémieB i've just added – Kavv Feb 06 '16 at 21:39
  • address_id cannot be null is the clue. Please check the mapped address field – Md Faraz Feb 06 '16 at 22:36
  • @MdFaraz i can see this pointer in stack trace, but i have checkedthe id with logger and it is present by value 2. So hibernate has to be trying to set the joincoulumn to null while deleting the entity, but i don't know why it happens and how to prevent it. – Kavv Feb 06 '16 at 22:40
  • Enable [SQL logging](http://stackoverflow.com/a/1713464/4754790). What is the statement causing the issue (the last logged one before the exception)? – Dragan Bozanovic Feb 06 '16 at 22:45
  • @DraganBozanovic ok i added logging from hibernate. Is that what you mean? – Kavv Feb 06 '16 at 22:52
  • Yes. It seems that `Contacts` table is the cause. Please post its mappings. – Dragan Bozanovic Feb 06 '16 at 22:59
  • Also, you don't seem to be dealing with `purchases` at all. What if there are purchases for the `Customers` you are deleting? – Dragan Bozanovic Feb 06 '16 at 23:01
  • Ok i posted it. The Contacts table has id, name, spend_money, age, contact_id (fk), country_id (fk) and address_id (fk) – Kavv Feb 06 '16 at 23:13

0 Answers0