-->
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.  [ 5 posts ] 
Author Message
 Post subject: Annotation and custom type
PostPosted: Fri May 11, 2007 7:58 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
Hibernate version: 3.2.2.ga

Annotation version: 3.2.1.ga

I wanted to implement my own enum type to save it to varchar not to int field in the database.

At first, I copied existed EnumType without any changes. When I used hibernate EnumType then method "setParameterValues" receives parameters such enum class name, but when I change @Type(type ="myEnumType") then method "setParameterValues" receives null not filled parameters. I understand that I can use @Parameter and set enum class manually. But everything works automatically with hibernate EnumType and I’d like such behavior with my custom enum type.

Is it possible?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 11, 2007 2:37 pm 
Beginner
Beginner

Joined: Wed Jun 15, 2005 1:28 pm
Posts: 39
Location: United States
To achieve this without a user type, you can annotate your enum like this:

@Enumerated(EnumType.STRING)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 12:18 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
busitech is correct

The reason you don't get any parameter is because the annotation (@Enumerated(EnumType.STRING)) is translated into a parameter for the enum user type in AnnotationBinder

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 8:14 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
Here's my enum

Code:
public enum AccountType implements NamedEnum {
    vertical("Virtual Business"), member("Member"), alert("Alert Subscriber");

    private AccountType(final String value) {
        this.value = value;
    }

    private String value;

    public String getValue() {
        return value;
    }

    public String toString() {
        return getValue();
    }
}


and i want to store in db not number (1,2 and etc) and not enum name( vertical, member ...) but this enum value property ("Virtual Business", "Member" and etc...).

For this purpose i wanted to create own UserType and expected to recieve params for this persistent property:

Code:
    @Type(type = "NamedEnumType")
    @Column(name = "account_type", updatable = false, length = 25)
    public AccountType getAccountType() {
        return accountType;
    }


Existed EnumType is working and it receieves params such enum class but my own which equals Hibernate EnumType ( I'll change it in the future when understand the problem wiith params) doesn't work.

I tried to add @Enumerated() but it didn't help.

With @Enumerated(EnumType.STRING) it's working but it stores enum name not my enum property.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 17, 2007 8:40 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You will have to do
Code:
@Type(type = "NamedEnumType", parameters=@Parameter(name="class", value="com.acme.AccountType"))
    @Column(name = "account_type", updatable = false, length = 25)
    public AccountType getAccountType() {
        return accountType;
    }

_________________
Emmanuel


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