I have hbm.xml as follows:
I was able to use that hbm file to geneate java file without probelm,
which is also listed below. However, when I try run java2hbm
to generare hbm file from java code, I got missing ID propery complain on UserLender.java.
Can some one help me?
hbm.xml file:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="UserLender"
table="USER_LENDER"
>
<meta attribute="class-description" inherit="false">
@hibernate.class
table="USER_LENDER"
</meta>
<composite-id name="comp_id" class="UserLenderPK">
<meta attribute="class-description" inherit="false">
@hibernate.id
generator-class="assigned"
</meta>
<key-property
name="userId"
column="USER_ID"
type="java.lang.Long"
length="10"
>
<meta attribute="field-description">
@hibernate.property
column="USER_ID"
</meta>
</key-property>
<key-property
name="lenderCode"
column="LENDER_CODE"
type="java.lang.String"
length="5"
>
<meta attribute="field-description">
@hibernate.property
column="LENDER_CODE"
</meta>
</key-property>
</composite-id>
<property
name="status"
type="java.lang.String"
column="STATUS"
length="1"
>
<meta attribute="field-description">
@hibernate.property
column="STATUS"
length="1"
</meta>
</property>
<!-- associations -->
</class>
</hibernate-mapping>
UserLender.java:
import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
/**
* @hibernate.class
* table="USER_LENDER"
*
*/
public class UserLender implements Serializable {
/** identifier field */
private UserLenderPK comp_id;
/** nullable persistent field */
private String status;
/** full constructor */
public UserLender(UserLenderPK comp_id, String status) {
this.comp_id = comp_id;
this.status = status;
}
/** default constructor */
public UserLender() {
}
/** minimal constructor */
public UserLender(UserLenderPK comp_id) {
this.comp_id = comp_id;
}
public UserLenderPK getComp_id() {
return this.comp_id;
}
public void setComp_id(UserLenderPK comp_id) {
this.comp_id = comp_id;
}
/**
* @hibernate.property
* column="STATUS"
* length="1"
*
*/
public String getStatus() {
return this.status;
}
public void setStatus(String status) {
this.status = status;
}
public String toString() {
return new ToStringBuilder(this)
.append("comp_id", getComp_id())
.toString();
}
public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( !(other instanceof UserLender) ) return false;
UserLender castOther = (UserLender) other;
return new EqualsBuilder()
.append(this.getComp_id(), castOther.getComp_id())
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(getComp_id())
.toHashCode();
}
}
UserLenderPK.java:
import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
/**
* @hibernate.id
* generator-class="assigned"
*
*/
public class UserLenderPK implements Serializable {
/** identifier field */
private Long userId;
/** identifier field */
private String lenderCode;
/** full constructor */
public UserLenderPK(Long userId, String lenderCode) {
this.userId = userId;
this.lenderCode = lenderCode;
}
/** default constructor */
public UserLenderPK() {
}
/**
* @hibernate.property
* column="USER_ID"
*
*/
public Long getUserId() {
return this.userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
/**
* @hibernate.property
* column="LENDER_CODE"
*
*/
public String getLenderCode() {
return this.lenderCode;
}
public void setLenderCode(String lenderCode) {
this.lenderCode = lenderCode;
}
public String toString() {
return new ToStringBuilder(this)
.append("userId", getUserId())
.append("lenderCode", getLenderCode())
.toString();
}
public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( !(other instanceof UserLenderPK) ) return false;
UserLenderPK castOther = (UserLenderPK) other;
return new EqualsBuilder()
.append(this.getUserId(), castOther.getUserId())
.append(this.getLenderCode(), castOther.getLenderCode())
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(getUserId())
.append(getLenderCode())
.toHashCode();
}
}