If you are asking for 1 HQL to insert into both tables, I believe that is not possible and practical. Even outside of hibernate, if you have to insert into 2 tables you will have to use 2 insert queries. You can however leverage triggers on 1 table to insert into the other but in this case you don't have values for hte second table available.
Alerternatively, you could use the following mapping to acheive the same:
Displayname.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="com.hibernate.forums">
<class
name="Displayname"
table="DISPLAYNAME"
>
<meta attribute="sync-DAO">false</meta>
<id
name="Id"
column="ID"
type="integer"
length="10"
>
<generator class="assigned"/>
</id>
<property
name="Title"
column="TITLE"
type="string"
not-null="false"
length="10"
/>
<one-to-one name="mainTable" class="Maintable" cascade="save-update"/>
</class>
</hibernate-mapping>
Maintable.hbm.xmlCode:
<hibernate-mapping package="com.hibernate.forums">
<class
name="Maintable"
table="MAINTABLE"
>
<meta attribute="sync-DAO">false</meta>
<id
name="Id"
column="ID"
type="integer"
length="10"
>
<generator class="assigned"/>
</id>
<property
name="Description"
column="DESCRIPTION"
type="string"
not-null="false"
length="10"
/>
</class>
</hibernate-mapping>
Sampe code for a cascading save:
Code:
SessionFactory factory = cfg.buildSessionFactory();
Session tSession = factory.openSession();
System.out.println("Configurations Ok!!!");
Maintable maintable = new Maintable();
maintable.setDescription("Descript");
Displayname name = new Displayname();
name.setId(new Integer(1));
name.setTitle("Title");
name.setMainTable(maintable);
Transaction tx = tSession.beginTransaction();
tSession.save(name);
tx.commit();
tSession.close();
Hope that helps.