-->
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.  [ 3 posts ] 
Author Message
 Post subject: Default column values with Annotations?
PostPosted: Fri Jun 23, 2006 7:30 am 
Newbie

Joined: Fri Jun 23, 2006 7:21 am
Posts: 2
Is there some way to set the default column value for columns with Annotations? I see there is a way with both the Property tag and Column tag in XML configuration, but I see nothing like that with Annotations. What am I missing?

Hibernate version:
hibernate-3.2.0.CR2 hibernate-annotations-3.2.0.CR1

Name and version of the database you are using:
PostgreSQL 8.1.4


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 23, 2006 8:36 am 
Regular
Regular

Joined: Wed Jan 11, 2006 12:49 pm
Posts: 64
Location: Campinas, Brazil
It can be done using a callback method:
Code:
@Entity
@EntityListeners({YourListener})
public class YourEntity {
    private String someProperty;
    // you know the rest
}

public class YourListener {
    @PrePersist
    public void prePersist(YourEntity e) {
        if (e.getSomeProperty() == null)
            e.setSomeProperty("some value");
    }
}

You can also annotate a method in the entity as @PrePersist and not create a listener.

_________________
Henrique Sousa
Don't forget to rate useful responses


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 23, 2006 8:43 am 
Newbie

Joined: Fri Jun 23, 2006 7:21 am
Posts: 2
Thank you.


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