-->
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.  [ 7 posts ] 
Author Message
 Post subject: Custom UserType for Entity?
PostPosted: Fri Dec 22, 2006 6:36 am 
Beginner
Beginner

Joined: Fri Jun 09, 2006 4:21 pm
Posts: 23
Location: Reading
Hi all,

I'd like to implement custom usertype for one of my entities. The question is, how to describe and handle the identity of the objects? I would really like Hibernate to generate the identites, like it does with @Id @GeneratedValue tags, but apparently this cannot be combined with custom usertypes, or can it?

All examples I have found so far use custom usertypes for "value" properties, which are mapped to one or several columns without dealing with any idenitity information whatsoever.

Can anyone confirm that while implementing custom types for entities I have to manage object Id manually and then handle Id property like any others in the custom type class?

Thank you,


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 22, 2006 8:52 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the type of an object is not related to the identiy generation (except some identifier generators assumes a numerical/integer type)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 22, 2006 6:48 pm 
Beginner
Beginner

Joined: Fri Jun 09, 2006 4:21 pm
Posts: 23
Location: Reading
Thanks for the answer, this is really a good news. But what I'm still unable to find is how to specify the type of my entity.
Code:
@org.hibernate.annotations.Type
is not applicable to classes.

I'd like to save the object as stand-alone, without referencing. Can I specify the custom type of the entity with annotations?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 22, 2006 6:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
why do you talk about the class here ? it is somehting related to the id property.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 22, 2006 7:37 pm 
Beginner
Beginner

Joined: Fri Jun 09, 2006 4:21 pm
Posts: 23
Location: Reading
Quote:
why do you talk about the class here ?

Because I'm trying to describe Entity, represented by a class. And also because I'm not too good at Hibernate, apparently :)

Quote:
it is somehting related to the id property.

Do you mean that I should specify usertype to Entity's Id property, like following?

Code:
@Entity
public class TransactionException extends RuntimeException {

    @org.hibernate.annotations.Type(
            type = "usertype.TransactionExceptionUserType"
    )
    @org.hibernate.annotations.Columns(columns = {
        @Column(name="exception"),
        @Column(name="stack")
            })

    @Id
    @GeneratedValue
    private Long id;

    ....
}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 23, 2006 5:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
ehh....i think we are talking pass eachother ;)

UserType is for values not entities.

Why do you want a usertype for entities anyway ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 23, 2006 10:42 am 
Beginner
Beginner

Joined: Fri Jun 09, 2006 4:21 pm
Posts: 23
Location: Reading
max wrote:
UserType is for values not entities.
Why do you want a usertype for entities anyway ?

Good question, now I realise I can do without it. In fact it is even better in a way to have an entity, and custom types only for it's property values. That way other standard properties may be mapped independently.

Thanks for the hint :)


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