My doubt is solved, I'll report (see below).
That is almost scratched customizing.
I hope this tool to support the case table don't have primary key and
expect this to future release.
Thanks to all.
-----------------------------------------------------------------------------------
[ FOR REFERENCE ]
-----------------------------------------------------------------------------------
1. edit *.hbm.xml related to the table to which another table's foreign-key targets.
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.2
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="org.ultimania.model.GroupInfo"
table="group_info"
lazy="false"
>
<composite-id
name="groupInfoPK" class="org.ultimania.pk.GroupInfoPK">
<key-property
name="groupId"
column="group_id"
type="int"
length="4"
/>
<!--
<key-property
name="groupName"
column="group_name"
type="java.lang.String"
length="20"
/> -->
</composite-id>
<!-- Customized -->
<property
name="groupName"
column="group_name"
type="java.lang.String"
length="20"
/>
<!-- Associations -->
<!-- derived association(s) for compound key -->
<!-- end of derived association(s) -->
<!-- bi-directional one-to-many association to RelationInfo -->
<set
name="relationInfos"
lazy="true"
inverse="true"
cascade="all"
>
<key>
<column name="group_id" />
</key>
<one-to-many
class="org.ultimania.model.RelationInfo"
/>
</set>
</class>
</hibernate-mapping>
-----------------------------------------------------------------------------------
2. create class file for primary key.
GroupInfoPK.java
Code:
package org.ultimania.pk;
import java.io.Serializable;
public class GroupInfoPK implements Serializable {
private Integer groupId;
public Integer getGroupId() {
return groupId;
}
public void setGroupId(Integer id) {
this.groupId = id;
}
public int hashCode() {
return (groupId).hashCode();
}
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (!(object instanceof GroupInfoPK)) {
return false;
}
GroupInfoPK other = (GroupInfoPK) object;
return this.groupId.equals(other.groupId);
}
public String toString() {
return groupId.toString();
}
}
-----------------------------------------------------------------------------------
3. edit the auto-generated class (change field which is defined as "unique index").package org.ultimania.model;
import java.io.Serializable;
import java.util.Set;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.ultimania.pk.GroupInfoPK;
/** @author Hibernate CodeGenerator */
public class GroupInfo implements Serializable {
/** identifier field */
private GroupInfoPK groupInfoPK;
/** identifier field */
private String groupName;
/** persistent field */
private Set relationInfos;
/** full constructor */
public GroupInfo(GroupInfoPK pk, String groupName, Set relationInfos) {
this.groupInfoPK = pk;
this.groupName = groupName;
this.relationInfos = relationInfos;
}
/** default constructor */
public GroupInfo() {
}
public GroupInfoPK getGroupInfoPK() {
return this.groupInfoPK;
}
public void setGroupInfoPK(GroupInfoPK pk) {
this.groupInfoPK = pk;
}
public String getGroupName() {
return this.groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public Set getRelationInfos() {
return this.relationInfos;
}
public void setRelationInfos(Set relationInfos) {
this.relationInfos = relationInfos;
}
public String toString() {
return new ToStringBuilder(this)
.append("groupId", getGroupInfoPK())
.append("groupName", getGroupName())
.toString();
}
}
-----------------------------------------------------------------------------------
4. an example to callCode:
public static void main(String[] args) {
Configuration config = new Configuration();
config = config.configure();
SessionFactory sessionFactory = config.buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
GroupInfo g1 = new GroupInfo();
GroupInfoPK gpk1 = new GroupInfoPK();
gpk1.setGroupId(new Integer(1));
g1.setGroupInfoPK(gpk1);
g1.setGroupName("group_1");
session.save(g1);
transaction.commit();
session.close();
}
-----------------------------------------------------------------------------------