Hibernate version:
2.6
Mapping documents:
<hibernate-mapping package="com.bo">
<class name="UserAction" table="user_action" lazy="true">
<many-to-one name="systemUser" class="SystemUser" column="system_user_id"/>
</class>
Code between sessionFactory.openSession() and session.close():
N/A
Full stack trace of any exception that occurs:
N/A
Name and version of the database you are using:
mysql
The generated SQL (show_sql=true):
n/a
Debug level Hibernate log excerpt:
n/a
So if I run hbm2java on the above looking hbm file, I will get a java file that does not compile.
Problem, I get a java file that looks like this..
import SystemUser;
import com.sun.OtherStuf.....
public class UserAction etc.....
so problem is the import SystemUser line , thats not legal because it tells me it cannot find SystemUser..
now this is fixable, if I use many-to-one like this
<many-to-one name="systemUser" class="com.bo.SystemUser" column="system_user_id"/>
and in the UserAction class, there is no import SystemUser and
systemUser is declared like
com.bo.SystemUser systemUser;
now I like to use many-to-one without specifying the package for SystemUser because I declared the package on <hibernate-mapping package="com.bo">, and both UserAction and SystemUser are in the same package.
problem actually comes from the class : net.sf.hibernate.tool.hbm2java.ClassName
public boolean inSamePackage(ClassName other) , it sees that SystemUser has a null package, ofcourse because I don't specify one..
So my million dollar question is this.
Am I supposed to have a fully qualified name of the class when declared a many-to-one, or is this a little buggy in the hbm2java.
If its a buggy.. what the best way to fix it?
I added a null check statement in class:
net.sf.hibernate.tool.hbm2java.ClassMapping
Code:
public void addImport(ClassName className) {
// if the package is java.lang or our own package don't add
if ( [color=red]className.getPackageName() != null[/color] && !className.inJavaLang() && !className.inSamePackage(generatedName) && !className.isPrimitive()) {
if(className.isArray()) {
imports.add( className.getFullyQualifiedName().substring(0,className.getFullyQualifiedName().length()-2) ); // remove []
} else {
imports.add( className.getFullyQualifiedName() );
}
}
}
Paul[/code]