-->
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.  [ 13 posts ] 
Author Message
 Post subject: hbm2java & interfaces & inheritance
PostPosted: Tue Feb 03, 2004 6:27 am 
Newbie

Joined: Tue Feb 03, 2004 6:18 am
Posts: 12
I want to create in hbm.xml this structure:

public interface IAudit {
public void setCreationDate(Date creationDate);
public void getCreationDate();
public void setLastUpdate(Date lastUpdate);
public void getLastUpdate();
}

public abstract BaseRow implements IAudit {
private Date creationDate, lastUpdate;
private Long id; //PK for each row
//Get and set for creationDate
...
//Get and set for lastUpdate
...
//Get and set for Id
...
}


I want that all my rows inherit from BaseRow, and I don't want to create a table for IAudit nor BaseRow( it's only a class to define a common type for row's PK (Long))

I have tried some things with hbm.xml files but nothing satifies my expectations. Anyone knows how can I do it?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 3:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
If those classes ain't persistent then you write them your self.

and then you say

<class name="whatever" ...>
<meta attribute="extends">BaseRow</meta>
</class>

btw. BaseRow sounds like a really horrible name for a class ? ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: More
PostPosted: Wed Feb 04, 2004 7:34 am 
Newbie

Joined: Tue Feb 03, 2004 6:18 am
Posts: 12
First, thanks for your response.

I write BaseRow (or RootRow if you prefer :)) , and I want that this class contains id (pk in each bd table). All rows in my system inherit BaseRow

I put a clause extends in hbm files but when hbm2java generates code dont put id in java files.

I prefer not to create BaseRow with joined class and discriminator, hibernate hbm2java tool can inherit the id from a java file?

How I do this?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 7:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
So - you have certain properties you DON'T want generated, right ?

Look at the meta docs - one of the attributes does that (can't remember top of my head right now ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: My example
PostPosted: Wed Feb 04, 2004 1:36 pm 
Newbie

Joined: Tue Feb 03, 2004 6:18 am
Posts: 12
This is the problem

I want to write an abstract class called RootRows, this row only contains this properties:

<class name="RootRow" ...>
<meta attribute = "implements">IAudit</meta>
<!-- IAudit is a interface in a java file with this methods set/get creationDate and set/get lastUpdate -->
<id name = "id" type = "java.lang.Long">
<generator class="native"/>
</id>
<property name = "creationDate" type = "java.lang.Date"/>
<property name = "lastUpdate" type = "java.lang.Date"/>
</class>

I dont want to maintain a table in my DB for rows of this type.

The rows of my system (rows with associated table in DB) inherit from RootRow (inherit id, creationDate, and lastUpdate). I would like to define each of this rows in a separate hbm.xml

<class name="Person">
<meta attribute = "extends">RootRow</meta>
<!-- get id, creationDate and lastUpdate from RootRow -->
<property name = "name" type = "java.lang.String"/>
</class>

It could be possible?

(Another question: hibernate could gen java interfaces?)

Thanks for your patience


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 3:50 pm 
Hibernate Team
Hibernate Team

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

So, don't write a hbm.xml for RootRow and write that particular class your self.

The properties you do NOT want generated for other classes (which easily can be in other hbm.xml's) you add <meta attribute="gen-property">false</meta>

If you want hbm2java to generate interface instead of class you do
<meta attribute="interface">true</meta>.


All this is listed in the docs about <meta> - please read it!

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 09, 2004 5:28 am 
Newbie

Joined: Tue Feb 03, 2004 6:18 am
Posts: 12
I have this hbm.xml for an interface:

<hibernate-mapping package="mypackage">
<meta attribute = "interface">true</meta>
<class name = "mypackage.ICreationAuditing">
<property name = "creationDate"
column = "creation_date"
type = "date"/>
</class>
</hibernate-mapping>


hbm2java generates ICreation.java (interface) but throws an exception. hbm2ddl does no accept it. What is wrong in syntax?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2004 3:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
and the exception is ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Exceptions: hbm2java , hbm2ddl
PostPosted: Tue Feb 10, 2004 4:46 am 
Newbie

Joined: Tue Feb 03, 2004 6:18 am
Posts: 12
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="mypackage.interfaces">
<meta attribute = "class-description">
Blah blah blah
</meta>
<class name = "mypackage.interfaces.ILastUpdateAuditing">
<meta attribute = "interface">true</meta>
<property name = "lastUpdate"
column = "last_update"
type = "date"/>
</class>
</hibernate-mapping>


hbm2java
********
GRAVE: Error parsing XML: file:ILastUpdateAuditing.hbm.xml(11)
org.xml.sax.SAXParseException: El elemento "class" no permite "property" aqu.
at org.apache.crimson.parser.Parser2.error(Parser2.java:3160)
at org.apache.crimson.parser.ValidatingParser$ChildrenValidator.consume(ValidatingParser.java:349)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1317)
at org.apache.crimson.parser.Parser2.content(Parser2.java:1779)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1507)
at org.apache.crimson.parser.Parser2.content(Parser2.java:1779)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1507)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:500)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:707)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:689)
at net.sf.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:98)
at com.lovenetic.deployment.RowCompiler.<init>(RowCompiler.java:28)
at com.lovenetic.deployment.RowCompiler.main(RowCompiler.java:41)
10-feb-2004 9:14:28 net.sf.hibernate.tool.hbm2java.CodeGenerator$1 error
GRAVE: Error parsing XML: file:ILastUpdateAuditing.hbm.xml(14)
org.xml.sax.SAXParseException: El elemento "class" requiere elementos adicionales.
at org.apache.crimson.parser.Parser2.error(Parser2.java:3160)
at org.apache.crimson.parser.ValidatingParser$ChildrenValidator.done(ValidatingParser.java:361)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1519)
at org.apache.crimson.parser.Parser2.content(Parser2.java:1779)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1507)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:500)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:707)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:689)
at net.sf.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:98)
at com.lovenetic.deployment.RowCompiler.<init>(RowCompiler.java:28)
at com.lovenetic.deployment.RowCompiler.main(RowCompiler.java:41)



hbm2ddl
*******
10-feb-2004 9:19:24 net.sf.hibernate.cfg.Environment <clinit>
INFO: Hibernate 2.1.1
10-feb-2004 9:19:24 net.sf.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
10-feb-2004 9:19:24 net.sf.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
10-feb-2004 9:19:24 net.sf.hibernate.cfg.Configuration addFile
INFO: Mapping file: ILastUpdateAuditing.hbm.xml
10-feb-2004 9:19:24 net.sf.hibernate.util.XMLHelper$ErrorLogger error
GRAVE: Error parsing XML: ILastUpdateAuditing.hbm.xml(11) El elemento "class" no permite "property" aqu.
10-feb-2004 9:19:24 net.sf.hibernate.util.XMLHelper$ErrorLogger error
GRAVE: Error parsing XML: ILastUpdateAuditing.hbm.xml(14) El elemento "class" requiere elementos adicionales.
10-feb-2004 9:19:25 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: mypackage.interfaces.ILastUpdateAuditing -> ILastUpdateAuditing
10-feb-2004 9:19:25 net.sf.hibernate.cfg.Configuration addFile
GRAVE: Could not configure datastore from file: ILastUpdateAuditing.hbm.xml
java.lang.NullPointerException
at net.sf.hibernate.mapping.PersistentClass.createPrimaryKey(PersistentClass.java:226)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:342)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1204)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:247)
at net.sf.hibernate.cfg.Configuration.addFile(Configuration.java:169)
at com.lovenetic.deployment.SchemaGen.main(SchemaGen.java:61)
Exception in thread "main" net.sf.hibernate.MappingException: java.lang.NullPointerException
at net.sf.hibernate.cfg.Configuration.addFile(Configuration.java:175)
at com.lovenetic.deployment.SchemaGen.main(SchemaGen.java:61)
Caused by: java.lang.NullPointerException
at net.sf.hibernate.mapping.PersistentClass.createPrimaryKey(PersistentClass.java:226)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:342)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1204)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:247)
at net.sf.hibernate.cfg.Configuration.addFile(Configuration.java:169)
... 1 more


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2004 7:58 am 
Newbie

Joined: Tue Feb 03, 2004 6:18 am
Posts: 12
anyone has defined an hbm.xml to generate a java interface? Could post an example code please?


Top
 Profile  
 
 Post subject: Re: Exceptions: hbm2java , hbm2ddl
PostPosted: Fri Feb 13, 2004 9:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
This is an exception message from the xml parser. You understand the error message better than me since it is in spanish(?) ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2004 1:47 pm 
Newbie

Joined: Tue Feb 03, 2004 6:18 am
Posts: 12
Upps, sorry!!This is in english

**
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="rows">
<meta attribute = "class-description">
blah blah
</meta>
<class name = "rows.ILastUpdateAuditing">
<meta attribute = "interface">true</meta>
<property name = "lastUpdate"
column = "last_update"
type = "date"/>
</class>
</hibernate-mapping>
**

English version:


*****
[java] Processing ILastUpdateAuditing.hbm.xml...
[java] 13-feb-2004 18:15:50 net.sf.hibernate.tool.hbm2java.CodeGenerator$1 error
[java] GRAVE: Error parsing XML: file:ILastUpdateAuditing.hbm.xml(14)
[java] org.xml.sax.SAXParseException: The content of element type "class" must match "(meta*,(cache|jcs-cache)?,(id|composite-id),discriminator?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|any|map|set|list|bag|idbag|array|primitive-array)*,(subclass*|joined-subclass*))".
[java] at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1213)
[java] at org.apache.xerces.validators.common.XMLValidator.reportRecoverableXMLError(XMLValidator.java:1851)
[java] at org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLValidator.java:1495)
[java] at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1204)
[java] at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
[java] at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
[java] at org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)
[java] at org.jdom.input.SAXBuilder.build(SAXBuilder.java:707)
[java] at org.jdom.input.SAXBuilder.build(SAXBuilder.java:689)
[java] at net.sf.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:98)
[java] at RowCompiler.<init>(RowCompiler.java:29)
[java] at RowCompiler.main(RowCompiler.java:42)
[java] Processed
ILastUpdateAuditing.hbm.xml...
*****


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2004 1:48 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You are missing an id property.


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