java - Hibernate many to one delets all parents when a child is deleted -


I have country and state objects. I intend that in a relationship from state to country, there are many unidirectional states. I do not want to store any reference to I have defined mapping below. When I even remove a state object, then all the countries are destroyed!

  & lt ;? XML version = "1.0"? & Gt; & Lt ;! DOCTYPE Hibernate-Mapping Public "- // Hibernate / Hibernate Mapping DTD // N" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> & Lt; Hibernate-Mapping & gt; & Lt; Class name = "places.ountry" table = "COUNTRY" dynamic-update = "true" & gt; & Lt ;! - Technical ID - & gt; & Lt; Id name = "name" type = "string" not saved-value = "new" column = "COUNTRY_NAME" & gt; & Lt; / Id & gt; & Lt ;! - Property - & gt; & Lt; Property name = "anonymous" column = "COMMON_NAME" /> & Lt; Property Name = "iso2Code" column = "ISO2_CODE" /> & Lt; Property Name = "iso3Code" column = "ISO3_CODE" /> & Lt; Property Name = "isoNumeric" column = "ISO_NUMERIC" /> & Lt; Property Name = "ituCode" column = "ITU_CODE" /> & Lt; Property Name = "ianaCode" column = "IANA_CODE" /> & Lt; / Square & gt; & Lt; Class name = "places.State" table = "STATE" dynamic-update = "true" & gt; & Lt ;! - Technical ID - & gt; & Lt; Name of the name = "name" type = "string" not saved-value = "new" column = "STATE_NAME" & gt; & Lt; / Id & gt; & Lt ;! - Property - & gt; & Lt; Asset name = "code" column = "STATE_CODE" /> & Lt; Many-to-one name = "country" column = "COUNTRY" no-null = "true" cascade = "none" class = "places.ountry" /> & Lt; / Square & gt; & Lt; / Hibernate-mapping & gt;  

Available mappings are okay, in fact, your mapping Use the following code to execute:

  session session = hibernateUtl.getSessionFactory (). GetCurrentSession (); Session.beginTransaction (); State aState = (state) session.load (state class, state id); Session.delete (aState); Committed to session.getTransaction ().  

Generates the following output:

 ... Choose State0_ STATE_NAME as Hibernate: STATE1_1_0_, STATE0_.STATE_CODE to STATE2_1_0_, state0_. Where STATE0_.STATE_NAME = from STATE STATE0_ as COUNTRY1_0_? Being in hibernation: Removing from state where STATE_NAME =? 3270 [Main] info org.hibernate.impl.SessionFactoryImpl - Close 

Things are working as expected, my country is still there.

Maybe show some code?


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -