Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1033631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:15:40+00:00 2026-05-16T14:15:40+00:00

Two classes: <class name=SpreadsheetImportTemplate table=spreadsheetimport_template> <id name=id type=int column=id unsaved-value=0> <generator class=native /> </id>

  • 0

Two classes:

 <class name="SpreadsheetImportTemplate" table="spreadsheetimport_template">
   <id name="id" type="int" column="id" unsaved-value="0">
     <generator class="native" />
   </id>
   <property name="name" type="java.lang.String" column="name" not-null="true" length="100" />
   <many-to-one name="creator" class="org.openmrs.User" not-null="true" />
   <property name="created" type="java.util.Date" column="date_created" not-null="true"
   length="19" />
   <many-to-one name="modifiedBy" column="changed_by" class="org.openmrs.User" not-null="false" />
   <property name="modified" type="java.util.Date" column="date_changed" not-null="false" length="19" />

  <!-- Associations -->
  <!-- bi-directional one-to-many association to SpreadsheetImportTemplateColumn -->
  <bag name="columns" cascade="all-delete-orphan" inverse="true">
    <key column="template_id" not-null="true" />
    <one-to-many class="SpreadsheetImportTemplateColumn" />
  </bag>
</class>

<class name="SpreadsheetImportTemplateColumn" table="spreadsheetimport_template_column">
  <id name="id" type="int" column="id" unsaved-value="0">
    <generator class="native" />
  </id>

  <many-to-one name="template" class="SpreadsheetImportTemplate" column="template_id" />

  <property name="columnName" type="java.lang.String" column="column_name" length="100" not-null="true" />
  <property name="dbTableDotColumn" type="java.lang.String" column="db_table_dot_column" length="100" not-null="true"/>
  <property name="extraData" type="java.lang.String" column="extra_data" length="100" not-null="false"/>

</class>

In java both have following with respective getters and setters:

    public class SpreadsheetImportTemplate {
 Integer id;
 String name;
    Collection<SpreadsheetImportTemplateColumn> columns = new ArrayList<SpreadsheetImportTemplateColumn>();
 Date created;
 Date modified;
 User creator;
 User modifiedBy;

 public SpreadsheetImportTemplate() {
 }
     ...

public class SpreadsheetImportTemplateColumn {
 Integer id;
 SpreadsheetImportTemplate template;
 String columnName;
 String dbTableDotColumn;
 String extraData;

 public SpreadsheetImportTemplateColumn() {
 }
    ...

However, if we have a SpreadsheetImportTemplate template with some columns, and we do a template.remove(0) and then a Hibernate saveOrUpdate, the relevant SpreadsheetImportTemplateColumn does not get deleted from the database 🙁

Any help appreciated.

Fyi, here is the relevant SQL that creates the databases:

CREATE TABLE IF NOT EXISTS `spreadsheetimport_template` (
    `id` int(32) NOT NULL auto_increment,
    `name` varchar(100) NOT NULL,
    `creator` int(11) NOT NULL default '0',
    `date_created` datetime NOT NULL default '0000-00-00 00:00:00',
    `changed_by` int(11) default NULL,
    `date_changed` datetime default NULL,
    PRIMARY KEY  (`id`),
    KEY `User who wrote this spreadsheet template` (`creator`),     
    KEY `User who changed this spreadsheet template` (`changed_by`),
    CONSTRAINT `User who wrote this spreadsheet template` FOREIGN KEY (`creator`) REFERENCES `users` (`user_id`),
    CONSTRAINT `User who changed this spreadsheet template` FOREIGN KEY (`changed_by`) REFERENCES `users` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;  

CREATE TABLE IF NOT EXISTS `spreadsheetimport_template_column` (
    `id` int(32) NOT NULL auto_increment,
    `template_id` int(32) NOT NULL default '0',
    `column_name` varchar(100) NOT NULL,
    `db_table_dot_column` varchar(100) NOT NULL,
    `extra_data` varchar(100),
    PRIMARY KEY  (`id`),
    KEY `Spreadsheet template to which this column belongs` (`template_id`),     
    CONSTRAINT `Spreadsheet template to which this column belongs` FOREIGN KEY (`template_id`) REFERENCES `spreadsheetimport_template` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:15:40+00:00Added an answer on May 16, 2026 at 2:15 pm

    Just relevant part

    SpreadsheetImportTemplate

    public class SpreadsheetImportTemplate {
    
        private Integer id;
        public Integer getId() { return id; }
        public void setId(Integer id) { this.id = id; }
    
        private Collection<SpreadsheetImportTemplateColumn> columns = new ArrayList<SpreadsheetImportTemplateColumn>();
        public Collection<SpreadsheetImportTemplateColumn> getColumns() { return columns; }
        public void setColumns(Collection<SpreadsheetImportTemplateColumn> columns) { this.columns = columns; }
    
        /**
         * set up both sides
         */
        public void addColumn(SpreadsheetImportTemplateColumn column) {
            getColumns().add(column);
    
            column.setTemplate(this);
        }
    
    }
    

    SpreadsheetImportTemplateColumn

    public class SpreadsheetImportTemplateColumn {
    
        private Integer id;
        public Integer getId() { return id; }
        public void setId(Integer id) { this.id = id; }
    
        private SpreadsheetImportTemplate template;
        public SpreadsheetImportTemplate getTemplate() { return template; }
        public void setTemplate(SpreadsheetImportTemplate template) { this.template = template; }
    
    }
    

    mapping

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping package="br.com._3589013.model.domain">
         <class name="SpreadsheetImportTemplate">
             <id name="id">
                 <generator class="native"/>
             </id>
             <bag name="columns" cascade="all,delete-orphan" inverse="true">
                 <key/>
                 <one-to-many class="SpreadsheetImportTemplateColumn"/>
             </bag>
        </class>
        <class name="SpreadsheetImportTemplateColumn">
             <id name="id">
                 <generator class="native"/>
             </id>
             <many-to-one name="template" class="SpreadsheetImportTemplate"/>
        </class>
    </hibernate-mapping>
    

    Test

    public class PersistenceTest {
    
        private static SessionFactory sessionFactory;
    
        private Serializable id;
    
        @BeforeClass
        public static void setUpClass() {
            Configuration c = new Configuration();
            c.addResource("mapping.hbm.3589013.xml");
    
            sessionFactory = c.configure().buildSessionFactory();
        }
    
        @Before
        public void setUp() throws Exception {
            SpreadsheetImportTemplate sit = new SpreadsheetImportTemplate();
            sit.addColumn(new SpreadsheetImportTemplateColumn());
    
            Session session = sessionFactory.openSession();
            session.beginTransaction();
    
            id = session.save(sit);
    
            session.getTransaction().commit();
        }
    
        @Test
        public void removedOrphan() throws Exception {
            Session session = sessionFactory.openSession();
            session.beginTransaction();
    
            List<SpreadsheetImportTemplateColumn> sitcList = session.createQuery("from SpreadsheetImportTemplateColumn").list();
    
            assertTrue(sitcList.size() == 1);
    
            SpreadsheetImportTemplate sit = (SpreadsheetImportTemplate) session.get(SpreadsheetImportTemplate.class, id);
            sit.getColumns().remove(sitcList.get(0));
    
            session.getTransaction().commit();
    
            assertTrue(sit.getColumns().size() == 0);
        }
    
    }
    

    It works fine!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose we have two classes: class Base { private: int x; public: void f();
I have two classes: public class MultilingualString { public int Id { get; set;
Let's say we have these two classes: public class Base { public static int
There are two classes: class Person include Mongoid::Document field :name embeds_many :addresses end class
Say i have the following two classes: public class User { public int ID
I have two domain classes: class A { String Name ... } class B
Lets say I have two classes: class A { [SortOrder(3)] public string Name {
I have these two classes: class Student { String name; String age ; }
I have two classes class Facebook { String fid String name User user static
I have two classes: class Foo{ public int FooId { get; set; } ...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.