-->
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.  [ 11 posts ] 
Author Message
 Post subject: hbm2java and composite id in H3
PostPosted: Tue Aug 02, 2005 11:14 pm 
Newbie

Joined: Mon Mar 07, 2005 7:18 pm
Posts: 16
Dear friends,

Problem: hbm2java in version 3 do not generate the class defined within the composite-id tag. But in version 2 it was generating the class co.omx.coon.resource.hibernate.beans.AccountGroupSubSupplierKey. is it a bug in version 3?

Here's my Map

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>

<class name="com.omx.common.resource.hibernate.beans.AccountGroupSubSupplier" table="ACCOUNT_GROUP_SUB_SUPLR" >

<composite-id class="com.omx.common.resource.hibernate.beans.AccountGroupSubSupplierKey" name="accountGrpSuplrKey" unsaved-value="none">
<key-property name="accountGroup" column="ACCOUNT_GROUP" type="string" ></key-property>
<key-property column="SUB_SUPLR_ID" name="subSupplierId" type="big_decimal"/>
</composite-id>

<property name="subSupplierStatus" column="SUB_SUPLR_STATUS" type="string" />
<property name="lastModDate" column="LAST_MOD_DATE" type="date" />
<property name="lastModBy" column="LAST_MOD_BY" type="string" />
</class>

</hibernate-mapping>


and here's the java code generated by hbm2java

package com.omx.common.resource.hibernate.beans;

import java.io.Serializable;
import org.apache.commons.lang.builder.ToStringBuilder;


/** @author Hibernate CodeGenerator */
public class AccountGroupSubSupplier implements Serializable {

/** nullable persistent field */
private String subSupplierStatus;

/** nullable persistent field */
private java.util.Date lastModDate;

/** nullable persistent field */
private String lastModBy;

/** full constructor */
public AccountGroupSubSupplier(String subSupplierStatus, java.util.Date lastModDate, String lastModBy) {
this.subSupplierStatus = subSupplierStatus;
this.lastModDate = lastModDate;
this.lastModBy = lastModBy;
}

/** default constructor */
public AccountGroupSubSupplier() {
}

public String getSubSupplierStatus() {
return this.subSupplierStatus;
}

public void setSubSupplierStatus(String subSupplierStatus) {
this.subSupplierStatus = subSupplierStatus;
}

public java.util.Date getLastModDate() {
return this.lastModDate;
}

public void setLastModDate(java.util.Date lastModDate) {
this.lastModDate = lastModDate;
}

Thanks for your time.
Chicagoram.
public String getLastModBy() {
return this.lastModBy;
}

public void setLastModBy(String lastModBy) {
this.lastModBy = lastModBy;
}

public String toString() {
return new ToStringBuilder(this)
.toString();
}

}



Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 2:15 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you are probably using hbm2java for hibernate 2, you should use the tools.hibernate.org for hibernate 3

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 12:35 pm 
Newbie

Joined: Mon Mar 07, 2005 7:18 pm
Posts: 16
Max,

I'm using org.hibernate.tool.hbm2java.Hbm2JavaTask.

I appreciate your help.

Thanks
chicgoram


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 12:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
use the latest tools instead - tools.hibernate.org

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 1:54 pm 
Newbie

Joined: Mon Mar 07, 2005 7:18 pm
Posts: 16
Max,

My ant task generates the following error

BUILD FAILED
D:\apps\omxactldr\platform\build.xml:56: Could not create type generatesources due to java.lang.NoSuchMethodException: org.hibernate.tool.ant.Hbm2JavaGeneratorTask.<init>(org.apache.tools.ant.Project)

and here's my ant target

<target name="codegen" >
<taskdef name="generatesources" classname="org.hibernate.tool.ant.Hbm2JavaGeneratorTask" classpathref="classpath.base"/>
<generatesources config="${src-dir}/hibernate.cfg.xml" output="${src-dir}">
<fileset dir="${map-dir}">
<include name="**/*.hbm.xml" />
</fileset>
</generatesources>
</target>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 1:54 pm 
Newbie

Joined: Mon Mar 07, 2005 7:18 pm
Posts: 16
Max,

My ant task generates the following error

BUILD FAILED
D:\apps\omxactldr\platform\build.xml:56: Could not create type generatesources due to java.lang.NoSuchMethodException: org.hibernate.tool.ant.Hbm2JavaGeneratorTask.<init>(org.apache.tools.ant.Project)

and here's my ant target

<target name="codegen" >
<taskdef name="generatesources" classname="org.hibernate.tool.ant.Hbm2JavaGeneratorTask" classpathref="classpath.base"/>
<generatesources config="${src-dir}/hibernate.cfg.xml" output="${src-dir}">
<fileset dir="${map-dir}">
<include name="**/*.hbm.xml" />
</fileset>
</generatesources>
</target>

Thanks for your help.

Chicagoram.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 11, 2006 12:08 pm 
Beginner
Beginner

Joined: Mon Aug 23, 2004 12:44 am
Posts: 25
Did you find the solution for this problem ?
If yes, can you let us know ?
Thanks,
EDH


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 11, 2006 1:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
as i wrote, use the libs that comes with the tools to avoid any version mismatches.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: error in generating ID subclass using maven plugin hbm2java
PostPosted: Fri Jun 29, 2007 2:36 pm 
Beginner
Beginner

Joined: Fri Jun 29, 2007 2:19 pm
Posts: 26
Location: Fremont, CA
Using maven plugin hibernate3-maven-plugin, I get the error in hbm2java

[INFO] Trace
org.hibernate.MappingException: class ProjectTeam$Id not found while looking for property: projectId


This only started coming as soon as I added <composite-id> to my intermediate table. Here is the hbm file

Code:
<hibernate-mapping>
    <class name="com.vsg.model.ProjectTeam" table="project_team" catalog="${dbunit.schema}" lazy="false" mutable="false">
        <comment></comment>
        <composite-id name="id" class="com.vsg.model.ProjectTeam$Id">
           <key-property name="projectId" access="field" column="project_id"/>
           <key-property name="userId" access="field" column="user_id"/>
        </composite-id>
        <many-to-one name="user" class="com.vsg.model.User" fetch="select" insert="false" update="false">
            <column name="user_id">
                <comment></comment>
            </column>
        </many-to-one>
        <many-to-one name="project" class="com.vsg.model.Project" fetch="select" insert="false" update="false">
            <column name="project_id">
                <comment></comment>
            </column>
        </many-to-one>
        <property name="startDate" type="date">
            <column name="start_date" length="10">
                <comment></comment>
            </column>
        </property>
        <property name="endDate" type="date">
            <column name="end_date" length="10">
                <comment></comment>
            </column>
        </property>
        <many-to-one name="role" class="com.vsg.model.Role" fetch="select">
            <column name="role_id" not-null="true">
                <comment></comment>
            </column>
        </many-to-one>
    </class>
</hibernate-mapping>

_________________
-shailesh


Top
 Profile  
 
 Post subject: Finally fixed it
PostPosted: Fri Jun 29, 2007 3:40 pm 
Beginner
Beginner

Joined: Fri Jun 29, 2007 2:19 pm
Posts: 26
Location: Fremont, CA
This is what I ended up doing
Changed
Code:
<composite-id name="id" class="com.vsg.model.ProjectTeam$Id">
           <key-property name="projectId" access="field" column="project_id"/>
           <key-property name="userId" access="field" column="user_id"/>
</composite-id>

to
Code:
<composite-id  name="id"  class="com.vsg.model.ProjectTeamId">
           <key-property name="projectId" column="project_id" type="long" access="field"/>
           <key-property name="userId" column="user_id" type="long" access="field"/>
</composite-id>


Changes
1. No inner class (changed ProjectTeam$Id --> ProjectTeamId)
2. defined types for the members of the composite key

_________________
-shailesh


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 02, 2007 4:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
1) hbm2java doesn't support generate innerclasses for composite-ids
2) specifying types for properties is a requirement to use a code generator (unless you want java.lang.Object for all your types)

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 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.