-->
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.  [ 3 posts ] 
Author Message
 Post subject: Advice on many-to-one and hbm2java
PostPosted: Wed Sep 22, 2004 3:11 pm 
Beginner
Beginner

Joined: Thu Jul 22, 2004 2:15 pm
Posts: 35
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]

_________________
--------------------------------------------------
To code or not to code... Is that a question?
--------------------------------------------------
Pritpal Dhaliwal


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 9:52 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Have you check the CVS version. I think this issue had come up previously.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 23, 2004 12:58 am 
Beginner
Beginner

Joined: Thu Jul 22, 2004 2:15 pm
Posts: 35
Hi David,

thanks for checkin out the post and the response. I have not checked the cvs yet. Will do that as time permits.

Paul

_________________
--------------------------------------------------
To code or not to code... Is that a question?
--------------------------------------------------
Pritpal Dhaliwal


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