-->
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.  [ 4 posts ] 
Author Message
 Post subject: Packages and hbm2java
PostPosted: Fri Mar 10, 2006 5:12 pm 
Newbie

Joined: Thu Jun 03, 2004 2:10 am
Posts: 19
I just ported from Hibernate to 2.1.8 to 3.1.2 and the actual code works well.

I am now porting the old hibernate tools to the newest version (3.1b4) and i've got the ant tasks working, but it seems that the new task does not actually insert the package identifier nor does it put the class in the right package directory (i assume this is from the same reason i'm always getting the default package).

I modified all the .hbms to use the new 3.0 DTD and they all have packages defined for the hibernate mapping (here is an example of one hbm):
--------------------------

<?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 package="com.mysite.p1.p2">

<class name="AppConfig" table="app_config">

<meta attribute="class-description">...</meta>

<meta attribute="implement-equals">true</meta>
<meta attribute="generated-class">BaseAppConfig</meta>

<id name="appConfigId"
type="java.lang.Long"
column="app_config_id"
unsaved-value="0">
<generator class="native"/>
</id>

<property name="name"
column="name"
type="string"
length="50"
not-null="true">
<meta attribute="use-in-equals">true</meta>
<meta attribute="use-in-tostring">true</meta>
</property>

<property name="value"
column="value"
type="string"
length="100"
not-null="false">
<meta attribute="use-in-tostring">true</meta>
</property>

<property name="description"
column="description"
type="string"
length="100"
not-null="false">
</property>

</class>

<query name="appconfig.getAll"><![CDATA[

select
a
from
AppConfig a

]]></query>

</hibernate-mapping>
--------------------------

The ant task is the following:

--------------------------


......

<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="app-classpath"/>

<target name="codegen">
<hibernatetool destdir="src">
<configuration configurationfile="src/hibernate.cfg.xml" />
<hbm2java />
</hibernatetool>
</target>

--------------------------

The generated class appears in the "src" root w/o a package name.
Anyone have any ideas?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 10, 2006 5:52 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
please show me the generated java code ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Generated class from example
PostPosted: Fri Mar 10, 2006 8:31 pm 
Newbie

Joined: Thu Jun 03, 2004 2:10 am
Posts: 19
// default package
// Generated Mar 11, 2006 2:29:57 AM by Hibernate Tools 3.1.0.beta4



public class BaseAppConfig implements java.io.Serializable {


// Fields

private Long appConfigId;
private String name;
private String value;
private String description;


// Constructors

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

/** minimal constructor */
public BaseAppConfig(String name) {
this.name = name;
}

/** full constructor */
public BaseAppConfig(String name, String value, String description) {
this.name = name;
this.value = value;
this.description = description;
}



// Property accessors

public Long getAppConfigId() {
return this.appConfigId;
}

public void setAppConfigId(Long appConfigId) {
this.appConfigId = appConfigId;
}

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public String getValue() {
return this.value;
}

public void setValue(String value) {
this.value = value;
}

public String getDescription() {
return this.description;
}

public void setDescription(String description) {
this.description = description;
}


/**
* toString
* @return String
*/
public String toString() {
StringBuffer buffer = new StringBuffer();

buffer.append(getClass().getName()).append("@").append(Integer.toHexString(hashCode())).append(" [");
buffer.append("name").append("='").append(getName()).append("' ");
buffer.append("value").append("='").append(getValue()).append("' ");
buffer.append("]");

return buffer.toString();
}


public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( (other == null ) ) return false;
if ( !(other instanceof BaseAppConfig) ) return false;
BaseAppConfig castOther = ( BaseAppConfig ) other;

return ( (this.getName()==castOther.getName()) || ( this.getName()!=null && castOther.getName()!=null && this.getName().equals(castOther.getName()) ) );
}

public int hashCode() {
int result = 17;


result = 37 * result + ( getName() == null ? 0 : this.getName().hashCode() );


return result;
}





}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 10, 2006 8:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
use fully qualified classname in generated-class and it will work.

_________________
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.  [ 4 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.