-->
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.  [ 15 posts ] 
Author Message
 Post subject: Hib3-annotations: how to use a not-stored parentobject?
PostPosted: Thu Jan 20, 2005 11:09 am 
Newbie

Joined: Wed Sep 01, 2004 3:06 am
Posts: 9
I've this class-structure with a parentobject that has the basics every hibernated object should have in my application (ID, version, etc). Now I don't want to store this objecttype, since it is never actually used, only its subclasses.
But I can't figure out how to nicely store the properties of this object in a non-general way, I'd rather not name all id-fields in my database 'ID'. So I have something like this:
Code:
class Identifier
{
    Long id;
    Date lastEditDate;
    public getId(){return id}
    public setId(Long newId){id = newId}
...
}

class RealObject extends Identifier
{
    String someProp;
...
}

<hibernate-mapping>
    <class name="SomeObject" table="SomeObjects">

        <id name="id" column="someObjectID">
            <generator class="identity"/>
        </id>

        <timestamp name="lastEditDate" />
        <property name="someProp" />
    </class>
</hibernate-mapping>


So what I want is to keep using this class-structure and run with Annotations. But I don't want that Identifier-class to be stored in the database (is it an Entity than or not?), I especially don't want a root-table for this objecttype where all objects have their identity-stuff stored... That doesn't strike me as very performant or nice database-usage.
But I do want to use the object's id/lastEditDate, without specifying another getId/getLastEditDate-set of methods for each class.

Is that possible, if so how? If not, should it be/what is a good alternative?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 21, 2005 10:53 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The hibernate-annotation implementation allows you to tag the super class elements wo mapping them as @Entity.
It will not be portable though (EJB3 speaking).

PS This may fail for Id I'm not sure. Let me know

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 21, 2005 11:10 am 
Newbie

Joined: Wed Sep 01, 2004 3:06 am
Posts: 9
I noticed I could use @Id at the higher level indeed. And had that incorporated (though not tested yet).

But I stopped redesigning it to use annotations for now, since it is working right now and although it is cleaner to use annotations, it isn't very easy to rewrite all .hbm.xml-files to the annotated version. One thing is for instance the use of caches.
The way @Version works isn't very clear either (I have a date-field, which is mapped using the timestamp-xml-tag, will it work with @Version?). Besides that, it is a bit unclear how to specify whether your string needs to be mapped to a text-field instead of a varchar.

These were the issues I ran into, which made me decide to keep the current xml-enabled configuration for a while longer and sort these things out when I've a bit more time for that project.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 21, 2005 11:48 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
ACM wrote:
it isn't very easy to rewrite all .hbm.xml-files to the annotated version. One thing is for instance the use of caches.

We're working on a tool doing such thing (early stages though)
Caches are settable in the hibernate.cfg.xml (it's the preffered way actually since it centralize this feature configuration)

Quote:
The way @Version works isn't very clear either (I have a date-field, which is mapped using the timestamp-xml-tag, will it work with @Version?).

It should work because the type is inferred byt the property type. I'vent tested it though. Let me know if it doesn't. Feedbacks welcome.

Quote:
Besides that, it is a bit unclear how to specify whether your string needs to be mapped to a text-field instead of a varchar.

I don't really get you on that point.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 21, 2005 1:10 pm 
Newbie

Joined: Wed Sep 01, 2004 3:06 am
Posts: 9
emmanuel wrote:
I don't really get you on that point.

A database has commonly 3 ways of storing character-data, commonly named 'character varying' or 'varchar', 'character' or 'char' and 'text' or 'clob'. While Java basically has only one.
With the .hbm.xml's you could just say something like type='text' to use a text-field instead of the default varchar, with the annotations I don't really see how I can easily do that, besides specifying the entire creation-line.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 21, 2005 1:28 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You have to use the columnDefinition attribute.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 24, 2005 6:44 am 
Newbie

Joined: Wed Sep 01, 2004 3:06 am
Posts: 9
emmanuel wrote:
You have to use the columnDefinition attribute.

That's exactly my point. With the current xml way of configuring the set-up, you can specify type="text" (or perhaps it'd be clob?), allowing Hibernate to figure out, using the Dialect, out what kind of field it should be.
With the annotated way, you need to specify the columnDefinition, even less abstract than the type... But the less-abstract way is also hard-compiled-in, making it even harder to have specific wishes if you'd want to create an application that can run on several databasesystems.

So if you want to use annotations and stay abstract from your database implementation, you can run into this particular problem.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 24, 2005 6:54 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Thats why you will be able to override annotations with external metadata (in XML usually) at some point. It's just not done so far.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 24, 2005 7:02 am 
Newbie

Joined: Wed Sep 01, 2004 3:06 am
Posts: 9
christian wrote:
Thats why you will be able to override annotations with external metadata (in XML usually) at some point. It's just not done so far.

Yeah, I understand that :) But since it in alpha now, this is the time to point to these kind of things, right?
Anyway, will that kind of abstraction become available in the annotated-way? Or is that one of the things one needs to override annotations?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 24, 2005 11:35 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I expect to add this specific features available through Hibernate. Please report it as a feature request in JIRA (HibernateExt project)

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Storing java.lang.String as a TEXT (in MySQL) field
PostPosted: Thu Feb 10, 2005 6:17 am 
Newbie

Joined: Thu Feb 10, 2005 6:02 am
Posts: 3
Sorry if I'm being dense, I just need to confirm something.

Am I to gather from the exchange above that there is currently no way to tell Hibernate to deal with a java.lang.String property as anything other than a VARCHAR in the database?

Cheers

_________________
Elmo


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 10, 2005 7:02 am 
Newbie

Joined: Wed Sep 01, 2004 3:06 am
Posts: 9
If you make that "hibernate-annotations", than yes. Only via a complete columnDefinition.

When you use Hibernate's xml-configuration it is perfectly possible.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 10, 2005 7:43 am 
Newbie

Joined: Thu Feb 10, 2005 6:02 am
Posts: 3
I see (I think). So if I'm using something like XDoclet to generate my XML definitions I can't do it?

So if I have XML as folows for a property and wanted to make use a TEXT field, what would I do. It's not immediately apparent to me.

Code:
        <property
            name="description"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="description"
        />


Also, is this feature available in Hibernate version 2 or is it just version 3?

Thanks for your help

_________________
Elmo


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 10, 2005 7:47 am 
Newbie

Joined: Thu Feb 10, 2005 6:02 am
Posts: 3
Ok, I was being dense. Sorry. :-S

I've just realised this is a feature of Hib-3 only.

Thanks for your time

_________________
Elmo


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 6:15 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
ACM wrote:
That's exactly my point. With the current xml way of configuring the set-up, you can specify type="text" (or perhaps it'd be clob?), allowing Hibernate to figure out, using the Dialect, out what kind of field it should be.
With the annotated way, you need to specify the columnDefinition, even less abstract than the type... But the less-abstract way is also hard-compiled-in, making it even harder to have specific wishes if you'd want to create an application that can run on several databasesystems.

So if you want to use annotations and stay abstract from your database implementation, you can run into this particular problem.

Done in CVS, use @Type(type="text")

_________________
Emmanuel


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