-->
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.  [ 31 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: H3 hbm2java – toString/ hashCode/ equals
PostPosted: Tue Aug 02, 2005 7:20 am 
Beginner
Beginner

Joined: Tue Jul 19, 2005 4:03 am
Posts: 34
Location: Aberdeen, UK
I just migrated to Hibernate3 and the migration itself went just fine. But I got an issue with the POJO code generation when using the new Ant Tool in the Eclipse plug-in http://www.hibernate.org/hib_docs/tools/ant/


These where the list of issues I got:
    1. Did not create any toString methods
    2. Strange implementation of hashCode and equal, resulting in NullPointerExceptions where it never had happened before. Why is the Common Lang Builder methods not used anymore?
    3. Only default constructors (but that issue has been raised and discussedn in an earlier thread)


To overcome these issues, I was forced to use the hbm2java in the Hibernate2 Toolset, which still works with Hibernate3.

I just wonder if there is anything I’m missing here or is this how it should work?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 02, 2005 7:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The H3 tools have been re-architected thus they are still beta. In addition there has been changes in targeted functionality (and stuff that has not been built as yet). If you can supply examples of the issues you have found it will help us sort these problems out. Thanks.


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

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
#1 known issue, good candidate for community contribution

#2 the hashcode/equals assumed that required fields were initialized, but i recently fixed this in cvs so this is not the case anymore (we dont use commons builder as we didn't like to add that dependency in the first place)

#3 you answered that yourself, another good candidate for community contribution

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 3:11 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
@max
i could spend some time at weekend in adding a "toString"-method and full-/ minimal- constructors to hbm2java ...
But do you know some other hb-users doing it? I want to avoid beeing the second/third doing this ;)

CVS-Head and a CVS-Diff to JIRA, right?

Are minimal- and full-constructors (as in HB2-hbm2java) enough? Or should it be configurable in hbm-files which fields should be excluded/included to the constructor(s)? Or the scope of the constructor(s)? etc. :)

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 3:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
no - I don't know of others doing it.

full-constructors:
http://opensource.atlassian.com/project ... se/HBX-317

tostring: no jira issue (create one if you please)

Diff against head yes.

There is some existing code for deducing the full constructors in Cfg2Java (look for "constructor") but it is incomplete.

You could take a look at the old hbm2java and find the corresponding code and see if you can "port" it.

Regarding flexibility then let us just start with something that works and let us add the flexibility later.

The toString() should be pretty "straightforward" - we should just avoid dependencies on commons builder.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 4:56 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
@max
ok, thanx!
i will put the patches to jira as soon as i'm ready.
If i've got questions i'll open a new thread.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 5:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
just keep it here (better for your credits and the search engine)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 5:51 pm 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
@max
toString() is working ...
is it better for you if i add one patch for "toString" and another for "constructor" or one patch for all of them?

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 3:46 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
@max
sorry, but i think i'm just to stupid :(

I've got an problem triing the "toString"-Patch ...

This exception is making me crazy:
Code:
Caused by: org.xml.sax.SAXParseException: Document root element "hibernate-confi
guration", must match DOCTYPE root "hibernate-configuration".
        at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1318
)
        at org.apache.xerces.validators.dtd.DTDValidator.reportRecoverableXMLErr
or(DTDValidator.java:1602)
        at org.apache.xerces.validators.dtd.DTDValidator.rootElementSpecified(DT
DValidator.java:576)
        at org.apache.xerces.framework.XMLParser.callStartElement(XMLParser.java
:1903)
        at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.disp
atch(XMLDocumentScanner.java:980)
        at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentS
canner.java:381)
        at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1208)
        at org.dom4j.io.SAXReader.read(SAXReader.java:465)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1213)
        ... 18 more
--- Nested Exception ---


For testing i've copied the "hibernate.cfg.xml" from "Configuration.xml" and my WDSC says "The XML is valid according to DTD".

Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <!-- a SessionFactory instance listed as /jndi/name -->
    <session-factory
        name="java:hibernate/SessionFactory">

        <!-- properties -->
        <property name="connection.datasource">java:/comp/env/jdbc/MyDB</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="show_sql">false</property>
        <property name="transaction.factory_class">
            org.hibernate.transaction.JTATransactionFactory
        </property>
        <property name="jta.UserTransaction">java:comp/UserTransaction</property>

        <!-- mapping files -->
        <mapping resource="org/hibernate/auction/Item.hbm.xml"/>
        <mapping resource="org/hibernate/auction/Bid.hbm.xml"/>

        <!-- cache settings -->
        <class-cache class="org.hibernate.auction.Item" usage="read-write"/>
        <class-cache class="org.hibernate.auction.Bid" usage="read-only"/>
        <collection-cache collection="org.hibernate.auction.Item.bids" usage="read-write"/>

    </session-factory>

</hibernate-configuration>


This is my test-build.xml

Code:
<project name="hbtest">

  <taskdef
    name="hibernatetool"
    classname="org.hibernate.tool.ant.HibernateToolTask">
     <classpath>
      <fileset dir="lib">
        <include name="**/*.jar"/>
      </fileset>         
       </classpath>
   </taskdef>
   
   <target name="test">
      
    <hibernatetool destdir=".">
   
      <configuration configurationfile="./hibernate.cfg.xml"/> <!-- annotated class/packages are specified in the hibernate.cfg.xml -->

      <hbm2java/>
    </hibernatetool>      
  </target>
</project>


I'm quite sure that i've done something stupid wrong, but searching in the forum doesn't help me ... therefore i've thought "try it with the config from docs" ... but that doesn't work either ...

Sources from HB3 and HBExt are from CVS.

It's a little bit awkward ... but i'm to stupid for that :(

Could you please help me out?

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 3:52 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
are you sure it is reading the right file ?

regarding the patches then submit them as separate patches if that is easy for you to do - otherwise just submit them as one.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 3:56 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
yes, because if i change something in the "hibernate.cfg.xml"-file the error-message changes.

Example:
Changing "<hibernate-configuration>" to "<hibernate-configuration2"> the exception changes to:

Code:
org.hibernate.HibernateException: Could not parse configuration: C:\Entwicklung\
hibernate\toolstest\hibernate.cfg.xml
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1223)
        at org.hibernate.cfg.Configuration.configure(Configuration.java:1191)
        at org.hibernate.tool.ant.ConfigurationTask.doConfiguration(Configuratio
nTask.java:78)
        at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(Configurati
onTask.java:50)
        at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateTo
olTask.java:158)
        at org.hibernate.tool.ant.GeneratorTask.configureExporter(GeneratorTask.
java:73)
        at org.hibernate.tool.ant.Hbm2JavaGeneratorTask.configureExporter(Hbm2Ja
vaGeneratorTask.java:37)
        at org.hibernate.tool.ant.GeneratorTask.execute(GeneratorTask.java:31)
        at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.ja
va:122)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
        at org.apache.tools.ant.Task.perform(Task.java:364)
        at org.apache.tools.ant.Target.execute(Target.java:341)
        at org.apache.tools.ant.Target.performTasks(Target.java:369)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
        at org.apache.tools.ant.Main.runBuild(Main.java:673)
        at org.apache.tools.ant.Main.startAnt(Main.java:188)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)
Caused by: org.dom4j.DocumentException: Stopping after fatal error: The element
type "hibernate-configuration2" must be terminated by the matching end-tag "</hi
bernate-configuration2>". Nested exception: Stopping after fatal error: The elem
ent type "hibernate-configuration2" must be terminated by the matching end-tag "
</hibernate-configuration2>".
        at org.dom4j.io.SAXReader.read(SAXReader.java:484)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1213)
        ... 18 more


Therefore i'm quite sure that it reads the right config-file.

An alternative good be to to use a properties-file ... but can i specify a hbm.xml-file there? Haven't done that before ... must read the docs :)

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 3:57 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
try using a header like this:

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 3:59 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
perhaps this information is helpful,too.

I'm having the following libs in my "lib"-directory:
commons-logging-1.0.4.jar
dom4j-1.6.1.jar
hibernate3.jar
hibernate-tools.jar
jtidy-r8-21122004.jar
log4j-1.2.9.jar
velocity-1.4.jar
velocity-tools-generic-1.1.jar
xerces-2.6.2.jar
xml-apis.jar


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 4:01 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
using the changed header doesn't work, too.

I've used the 'vi' to look for some 'special characters', removed empty lines ... but it doesn't help.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 4:21 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
weird

_________________
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.  [ 31 posts ]  Go to page 1, 2, 3  Next

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.