-
1. Re: NOT NULL columns with a DEFAULT
oskar.carlstedt Apr 12, 2007 5:01 AM (in response to mtuckah)I have the same problem. Did you find any answer/solution for this?
Kind regards
Oskar -
2. Re: NOT NULL columns with a DEFAULT
uagardx Apr 12, 2007 5:24 AM (in response to mtuckah)"oskar.carlstedt" wrote:
I have the same problem. Did you find any answer/solution for this?
Kind regards
Oskar -
3. Re: NOT NULL columns with a DEFAULT
fhh Apr 12, 2007 5:27 AM (in response to mtuckah)
Not sure if this is what you want: You can simply set a default value on the java side, either in the constructor or using the factory pattern.
As far as I know there is no JPA way to set a default value.
Regards
Felix -
4. Re: NOT NULL columns with a DEFAULT
oskar.carlstedt Apr 12, 2007 11:18 AM (in response to mtuckah)Hi!!
No It is not exactly what I want. I solved everything by using inheritance and the SINGE_TABLE inheritance method. Then I could skip my property I didn't want to include.
But originally, I have a database specifying the default value. This value is used by other applications too. So to centralize the default value, we declared it in the database - Therefore, I don't want to set the default value in my implementation. Maybe this is something to report as a new annotation for ejb3. I don't think I'm the only one that is modeling a persistence layer on an existing database.
Anyway, I resolved my problem by using inheritance.@Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "discriminator", discriminatorType = DiscriminatorType.STRING) @Table(name = "THE_TABLE") public class GenericEntityBean implements Serializable { @Id @Column(name = "id") @GeneratedValue(strategy = GenerationType.IDENTITY) protected Integer id; @Column(name = "COMMON_VALUE") protected String commonValue; ... } @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "discriminator") @DiscriminatorValue(name = "SPECIFIC") public class SpecificEntityBean extends GenericEntityBean implements Serializable { @Column(name = "ANOTHER_SPECIFIC_VALUE") protected String anotherSpecificValue; ... }
Best Regards
Oskar -
5. Re: NOT NULL columns with a DEFAULT
fhh Apr 12, 2007 6:47 PM (in response to mtuckah)I don't see how that soved your problem.
Regards
Felix -
6. Re: NOT NULL columns with a DEFAULT
oskar.carlstedt Apr 13, 2007 4:25 AM (in response to mtuckah)Hi!!
Dtabase columns that are not part of the used implementation (not mapped by properties in the class) are not exposed in the SQL statement to the database - which is exactly what I want (the database shall set this value, not the sql statement).
Regards
Oskar