File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes entity Boolean field default value Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "entity Boolean field default value" Watch "entity Boolean field default value" New topic
Author

entity Boolean field default value

Alexander Curvers
Greenhorn

Joined: Apr 03, 2009
Posts: 26
whats the best way to specify a defailt value for a Boolean entity field,
i would like it to be false but now i get null when i use the getter
even though i set it false in the constructor of the entity it gets set to null when the entity is loaded from database (in the database the value is null by default)
i would like to use annotations so that the table and column are generated in the DB with a default value for the column..
Aurelian Tutuianu
Ranch Hand

Joined: May 13, 2004
Posts: 86
First, JPA does not provide an explicit way to set default values. Use Hibernate annotations for specific defaults.
Still you can do the same thing using @Column and @PrePersist.
- nullable to set column to not allow null values
- columnDefinition - to give a default value (pay attention, this is an sql specific vendor syntax)

If you want to be independent of db, try @PrePersist to set default value like here:


Hope it helped![/img]


http://javasign.blogspot.com/
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: entity Boolean field default value
 
Similar Threads
EJB create not using default value for not null column
Data conversion in Hibernate
Hibernate: Default Binding of database field
JPA Mapping Exception
Problem with Mapping between 1 bit column and boolean field