-->
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.  [ 1 post ] 
Author Message
 Post subject: Default DB value for a column
PostPosted: Tue Aug 28, 2007 4:48 am 
Newbie

Joined: Tue Jul 12, 2005 5:17 am
Posts: 9
Hi, All!
I have a very simple table with some data columns and a kind of timestamp column with "sysdate" default value defined:

Code:
package me.hibernate.bean;
import org.hibernate.Session;
import java.util.List;
public class LogApplication {
   private String lolParameters;
   public String getLolParameters() {
      return lolParameters;
   }
   public void setLolParameters(String lolParameters) {
      this.lolParameters = lolParameters;
   }
   private java.util.Date lolDate;
   public java.util.Date getLolDate() {
      return lolDate;
   }
   public void setLolDate(java.util.Date lolDate) {
      this.lolDate = lolDate;
   }
   private String lolPlace;
   public String getLolPlace() {
      return lolPlace;
   }
   public void setLolPlace(String lolPlace) {
      this.lolPlace = lolPlace;
   }
   private Integer lolCod;
   public Integer getLolCod() {
      return lolCod;
   }
   public void setLolCod(Integer lolCod) {
      this.lolCod = lolCod;
   }
   private String lolUtiCod;
   public String getLolUtiCod() {
      return lolUtiCod;
   }
   public void setLolUtiCod(String lolUtiCod) {
      this.lolUtiCod = lolUtiCod;
   }
}


The mapping is:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="me.hibernate.bean.LogApplication" table="LOG_APPLICATION">
        <id name="lolCod" column="LOL_COD">
            <generator class="sequence">
                <param name="sequence">S_LOG_APPLICATION</param>
            </generator>
        </id>
        <property name="lolParameters" column="LOL_PARAMETERS" />
        <property name="lolDate">
           <column name="LOL_DATE" default="sysdate" />
        </property>
        <property name="lolPlace" column="LOL_PLACE" />
        <property name="lolUtiCod" column="LOL_UTI_COD" />
    </class>
</hibernate-mapping>


My problem that Hibernate doesn't see default value defined for lolDate column. When I try to insert any line into this table it generates me an SQL like:

Code:
insert into LOG_APPLICATION (LOL_PARAMETERS, LOL_DATE, LOL_PLACE, LOL_UTI_COD, LOL_COD) values (?, ?, ?, ?, ?)


followed by exception
Code:
ORA-01400: cannot insert NULL into ("ME"."LOG_APPLICATION"."LOL_DATE").


If I omit lolDate property in mapping, insert works, but of course java field is not mapped.
Or I can use
Code:
<property name="lolDate" column="LOL_DATE" insert="false" />

, but in this case I'll not be able to change lolDate value if I don't want to use a default one.

How should I write my mapping ?

Thank you, AK.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.