-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: composite-id problem please help
PostPosted: Tue Jul 06, 2004 6:11 pm 
Beginner
Beginner

Joined: Wed Jun 09, 2004 2:49 pm
Posts: 25
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();
}

}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 06, 2004 8:11 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
JavaToHBM is deprecated and will not be a part of Hibernate3. Use XDoclet if you want to create the HBMs from the Java code. There are examples; see Tools example as a start.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.